我想在变量中存储一个以后使用的命令(不是命令的输出,而是命令本身).
我有一个简单的脚本如下:
command="ls";
echo "Command: $command"; #Output is: Command: ls
b=`$command`;
echo $b; #Output is: public_html REV test... (command worked successfully)
然而,当我try 一些更复杂的东西时,它失败了.例如,如果我
command="ls | grep -c '^'";
输出为:
Command: ls | grep -c '^'
ls: cannot access |: No such file or directory
ls: cannot access grep: No such file or directory
ls: cannot access '^': No such file or directory
如何将这样一个命令(带有管道/多个命令)存储在变量中以供以后使用?