在阅读了bash手册之后,关于这post页.
我仍然无法理解eval
命令的具体功能,以及它的典型用途.例如,如果我们这样做:
bash$ set -- one two three # sets $1 $2 $3
bash$ echo $1
one
bash$ n=1
bash$ echo ${$n} ## First attempt to echo $1 using brackets fails
bash: ${$n}: bad substitution
bash$ echo $($n) ## Second attempt to echo $1 using parentheses fails
bash: 1: command not found
bash$ eval echo \${$n} ## Third attempt to echo $1 using 'eval' succeeds
one
这里到底发生了什么?美元符号和反斜杠是如何联系在一起的?