1

I read this post: https://superuser.com/questions/304807/brace-expansion-run-several-commands-instead-of-expanding-on-one-line and tried its eval echo way of expansion. Why are the two commands below different?


Command 1:

$ eval echo\ {a,b,c}\;

Result 1:

a
b
c

Command 2:

$ eval echo\ {a,b,c} \;

Result 2:

a echo b echo c
4

1 回答 1

5

eval只是令人困惑的事情,所以摆脱它:

$ echo echo\ {a,b,c}\;
echo a; echo b; echo c;
$ echo echo\ {a,b,c} \;
echo a echo b echo c ;

这应该使正在发生的事情变得显而易见。在第一种情况下,eval 执行三个不同的 echo 命令。在第二种情况下,它只评估一个将字符串 'a echo b echo c' 作为参数的命令。

于 2015-11-08T21:50:14.497 回答