Function Description: Tell the shell to remove the eval parameters and re-calculate the contents of the parameters.
Syntax: eval [parameter]
Supplementary Note: Eval can read a series of parameters and then execute according to the characteristics of the parameters themselves.
Parameters: Unlimited number of parameters, separated from each other by semicolons.
1. Scan it two times before executing the command line, and then compute the contents of the parameter again.
Copy CodeThe code is as follows:
[[email protected] blue]# a= "ls |more"
[Email protected] blue]# $a #ls
Will | And more as arguments, instead of displaying files by page
Copy CodeThe code is as follows:
Ls:cannot access |more:no such file or directory
[Email protected] blue]# eval $a #取出
Their parameters and execute them again
Copy CodeThe code is as follows:
1
1.cpp
2
2.cpp
3
3.cpp
[[email protected] test]# a= "123"
[[email protected] test]# echo ' ${' "A" '} '
${a}
[[Email protected] test]# eval echo ' ${' "A" '} ' #再次执行 ${a} command
123
2.eval get the last parameter
Copy CodeThe code is as follows:
[[email protected] blue]# echo ' eval echo \$$# ' > Last
[email protected] blue]# cat Last
Eval echo \$$#
[Email protected] blue]#./last 1 2 3 4
4
Plus other advanced usage supplements!
Eval is a flexible application of the Bash shell command-line processing rules to construct "smart" commands for complex functions.
The above-mentioned command is an eval of one of the most common applications, which repeats 1 command-line parameter passing procedures and executes commands purely.
In fact, it is bash's difficult point, is the Advanced Bash Programmer's compulsory skill.
Example of use of eval in shell