Syntax: eval cmdline
Eval will scan the back of the CmdLine two times , if after the first scan, cmdline is a normal command, then execute this command;
If the cmdline contains an indirect reference to a variable, the semantics of the indirect reference is guaranteed.
Examples are as follows:
Func 11 22 33 44
If you want to output the last parameter 44, you can use the following command:
Echo $4
But if we don't know a few parameters, to output the last parameter, you might think of using $ #来输出最后一个参数,
If you use the command:
echo "\$$#"
The result is $4, not the 44 we want. Here comes the question of an indirect reference to a variable, our intention is to output $4, the default
case, the command ignores the case where the variable is referenced indirectly.
At this point, you can use the eval command.
Eval echo "\$$#"
The resulting result is 44.
Reference:
Use of Eval in the shell: http://doudouclever.blog.163.com/blog/static/175112310201252111104169/
Eval in Shell