Unix/Linux Go Back    


Shell Programming and Scripting 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 Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago   -   Original Discussion by april
april's Unix or Linux Image
april april is offline
Registered User
 
Join Date: Apr 2007
Last Activity: 18 May 2018, 10:57 AM EDT
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Combine 2 Commands

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


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

Thank you.
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago   -   Original Discussion by april
jim mcnamara's Unix or Linux Image
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 27 May 2018, 7:27 PM EDT
Location: NM
Posts: 11,394
Thanks: 617
Thanked 1,162 Times in 1,069 Posts


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

I do not see what that gets you, but it is correct syntax
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago   -   Original Discussion by april
april's Unix or Linux Image
april april is offline
Registered User
 
Join Date: Apr 2007
Last Activity: 18 May 2018, 10:57 AM EDT
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
I don't use Unix a lot so I was just wondering if it can be done.

I tried this and it failed miserably.


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

    #4  
Old Unix and Linux 1 Week Ago   -   Original Discussion by april
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 28 May 2018, 3:43 AM EDT
Location: Aachen, Germany
Posts: 12,756
Thanks: 417
Thanked 3,923 Times in 3,607 Posts
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:



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

The Following User Says Thank You to RudiC For This Useful Post:
jim mcnamara (1 Week Ago)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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
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



All times are GMT -4. The time now is 04:22 AM.