Function Description: Tell the shell to remove the eval parameters, recalculate the contents of the parameters.
Syntax: eval [parameters]
Supplemental Note: Eval can read a series of parameters and then perform them according to the characteristics of the parameters themselves.
Parameters: Unlimited number of arguments, separated by semicolons.
1. Scan it two times before executing the command line, and then calculate the contents of the parameter again.
Copy Code code as follows:
[root@localhost blue]# a= "ls |more"
[Root@localhost blue]# $a #ls
Will | And more as a parameter, rather than a file as a page display
Copy Code code as follows:
Ls:cannot access |more:no such file or directory
[Root@localhost blue]# eval $a #取出
Their parameters and execute them again
Copy Code code as follows:
1
1.cpp
2
2.cpp
3
3.cpp
[Root@localhost test]# a= "123"
[Root@localhost test]# Echo ' ${' "A" '} '
${a}
[Root@localhost test]# eval echo ' ${' "A ' '} ' #再次执行 ${a} command
123
2.eval get last parameter
Copy Code code as follows:
[Root@localhost blue]# Echo ' eval echo \$$# ' > Last
[Root@localhost blue]# Cat Last
Eval echo \$$#
[Root@localhost blue]#./last 1 2 3 4
4
Additional advanced usage is added later!
Eval is a flexible application of the bash shell command-line processing rules and constructs the "smart" command to implement complex functionality.
The command mentioned above is one of the most common applications of Eval, which repeats 1 command-line parameter passes and simply executes commands.
It's a hard nut to bash and a compulsory skill for advanced bash programmers.