Example of use of eval in shell

Source: Internet
Author: User
Tags eval

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.