Pipe inside variable isn't working in bash

Reply

Join Date: Jul 2003
Posts: 13
Reputation: Reginald0 is an unknown quantity at this point 
Solved Threads: 0
Reginald0 Reginald0 is offline Offline
Newbie Poster

Pipe inside variable isn't working in bash

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 1
Reputation: juppe10a is an unknown quantity at this point 
Solved Threads: 0
juppe10a juppe10a is offline Offline
Newbie Poster

Re: Pipe inside variable isn't working in bash

 
0
  #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 Quick reply to this message  
Join Date: Jul 2003
Posts: 13
Reputation: Reginald0 is an unknown quantity at this point 
Solved Threads: 0
Reginald0 Reginald0 is offline Offline
Newbie Poster

Re: Pipe inside variable isn't working in bash

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC