Eval in Shell

Source: Internet
Author: User

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

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.