Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个变量,当我回显时,它看起来像这样:
#echo $var awk '{print $7 " " $6 " " $8 " "}'
但如果我尝试类似
#ls -lah | exec $var awk: '{print awk: ^ invalid char ''' in expression
我究竟做错了什么?
而不是exec你需要调用eval:
exec
eval
ls -lah | eval $var
但是这里有两个警告:
ls
只需将 awk 脚本放在变量中
var='{print $7 " " $6 " " $8 " "}' ls -lah | awk "$var"