Combine 2 Commands

Hello,
I have the following code. I wonder if it can be combined into 1 command.

y=`ls -1| tail -n 1`
m=${y%.abc}

Thank you.

y=`ls -1| tail -n 1` && m=${y%.abc}

I do not see what that gets you, but it is correct syntax

I don't use Unix a lot so I was just wondering if it can be done.

I tried this and it failed miserably.

m=${`ls -1| tail -n 1`%.abc}

Using shell's "Parameter Expansion" (here:"Remove matching suffix pattern") doesn't allow you to do multiple operations in one command, you always need to use an interim variable.
You could, on the other hand, extend the "command substitution" pipe in the first place:

y=`ls -1 | tail -n 1 | sed 's/\.abc$//'`
1 Like