shell eval 指令

eval:

在《Advanced Bash-Scripting Guide》中有详细介绍:

eval arg1 [arg2] ... [argN]

Combines the arguments in an expression or list of expressions and evaluates them. Any variables within the expression are expanded. The net result is to convert a string into a command.

主要的意思是,eval 把所有的参数合并成一个表达式,并执行这个表达式,其中最重要的一点是eval 执行的表达式中的参数会进行一次拓展,(注意是进行一次拓展,而不是多次)。

eg.

Each invocation of eval forces a re-evaluation of its arguments.
a='$b'
b='$c'
c=d
echo $a            # $b
# First level.
eval echo $a    # $c
# Second level.
eval eval echo $a             # d
# Third level.

更详细可以参见《ABSG》

你可能感兴趣的:(shell eval 指令)