|
eval [arg ...]
The args are read and concatenated together into a single command. This command is then read and executed by the shell, and its exit status is returned as the value of eval. If there are no args, or only null arguments, eval returns 0.
(args 被读取并连结成单独一个命令。接着,这个命令被 shell 读取并执行,其退出状态作为 eval 的值返回。如果没有 args ,或者只有空的声明,eval 就只返回 0)
举例说明:foo=10
x=foo
y='$'$x
echo $y
上面的脚本输出: $foo
使用 eval 修改上面的脚本:foo=10
x=foo
eval y='$'$x
echo $y
结果输出为 10。因此,eval 看起来有点像给 foo 附加了个 $ 。也就是说,它得到了一个变量的值,然后再把这个值当成一个变量,最后求出这个变量的值。
eval 很有用,它能产生新的代码且可以动态地运行。它尽管使得脚本的调试变得复杂,但它另一方面可以使你处理一些困难甚至看起来是不可能的事情。
----------------
参考:
(1)man
(2)beginning.linux.programming 4 edition |
|