943,502 Members | Top Members by Rank

Ad:
Jan 30th, 2004
0

Pipe inside variable isn't working in bash

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reginald0 is offline Offline
13 posts
since Jul 2003
Jan 30th, 2004
0

Re: Pipe inside variable isn't working in bash

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
juppe10a is offline Offline
1 posts
since Jan 2004
Jan 30th, 2004
0

Re: Pipe inside variable isn't working in bash

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Reginald0 is offline Offline
13 posts
since Jul 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: $paths
Next Thread in Shell Scripting Forum Timeline: C++ and CGI





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC