Home Man
Today's Posts

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Combine 2 Commands

shell scripts

Login to Reply

Thread Tools Search this Thread
# 1  
Old 05-18-2018
Combine 2 Commands

I have the following code. I wonder if it can be combined into 1 command.
y=`ls -1| tail -n 1`

Thank you.
# 2  
Old 05-18-2018
y=`ls -1| tail -n 1` && m=${y%.abc}

I do not see what that gets you, but it is correct syntax
# 3  
Old 05-18-2018
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}

# 4  
Old 05-18-2018
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$//'`

The Following User Says Thank You to RudiC For This Useful Post:
jim mcnamara (05-18-2018)
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Combine two awk commands mirusnet Shell Programming and Scripting 4 09-06-2017 08:32 AM
Combine multiple commands andre666 Shell Programming and Scripting 6 11-25-2016 09:58 AM
Combine awk commands into one SkySmart Shell Programming and Scripting 5 08-18-2016 05:56 AM
Combine multiple awk commands kamauv234 Shell Programming and Scripting 6 06-14-2014 03:12 AM
Combine several commands in a bash script georgi58 Shell Programming and Scripting 9 10-12-2013 09:16 AM
How to combine awk and bash commands in script ? Akshay Hegde Shell Programming and Scripting 10 03-01-2013 11:47 PM
Can I combine these two commands into one? boyboy1212 Shell Programming and Scripting 2 03-28-2011 06:01 AM
nawk, combine commands numele Shell Programming and Scripting 2 03-17-2010 12:03 PM
Combine commands Spoiler UNIX for Dummies Questions & Answers 2 05-30-2009 04:56 PM
Combine Two Commands Output 33junaid Shell Programming and Scripting 16 08-13-2007 08:31 AM

All times are GMT -4. The time now is 02:57 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
Show Password