RSS Forums RSS
Please support our Shell Scripting advertiser: Programming Forums
Views: 7682 | Replies: 2
Reply
Join Date: Jul 2003
Location: Brazil
Posts: 13
Reputation: Reginald0 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
Reginald0 Reginald0 is offline Offline
Newbie Poster

Pipe inside variable isn't working in bash

  #1  
Jan 30th, 2004
Hi, folks!

See the examples:

bash$ X="ls"; $X
file1 file2 file3
*** Works correctly!

bash$ X="ls | wc"; $X
ls: |: No such file or directory
ls: wc: No such file or directory
*** Doesn't work!

How to make the last command work correctly as first?

Thanks in advance!

Reginald0
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2004
Posts: 1
Reputation: juppe10a is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
juppe10a juppe10a is offline Offline
Newbie Poster

Re: Pipe inside variable isn't working in bash

  #2  
Jan 30th, 2004
Hi,

if you want to store command result in variable use back quote:
# X=`ls | wc`
# echo $X.

or use command alias:
# alias X="ls | wc"
# X
Reply With Quote  
Join Date: Jul 2003
Location: Brazil
Posts: 13
Reputation: Reginald0 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 0
Reginald0 Reginald0 is offline Offline
Newbie Poster

Re: Pipe inside variable isn't working in bash

  #3  
Jan 30th, 2004
juppe10a,

It's not exactly what I was looking for, cause the command result isn't important to store to a variable, but the command execution itself.
I found a perfect way to do that:

# X="ls | wc"; eval $X

Simple but functional.

Thanks anyway!

Reginald0
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:07 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC