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!



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


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!


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.