How to store a command in a variable in a shell script?

The Solution to How to store a command in a variable in a shell script? is


Use eval:

x="ls | wc"
eval "$x"
y=$(eval "$x")
echo "$y"

~ Answered on 2011-04-11 00:38:21


Most Viewed Questions: