The eval command in Linux

Source: Internet
Author: User

This command has not been used before, on the Internet to check the information, I think people write very well, so copied over.

Title: Use of the Linux command eval
Links: http://blog.chinaunix.net/uid-21411227-id-1826706.html
Title: eval in the Linux shell
Links: http://www.2cto.com/os/201311/255577.html

Syntax: eval cmdline

Eval will perform a two-pass scan of the subsequent cmdline, execute this command if CmdLine is a normal command after the first sweep of the face, and if CmdLine contains an indirect reference to the variable, the semantics of the introduction reference is guaranteed.

Examples are as follows:

Set 11 22 33 44

If you want to output the most recent parameter, which is 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 what we want. 44. Here is a reference to a variable introduction to the problem, our intention is to output $4, by default, after the command ignores variable introduction reference case.

At this point, you can use the eval command.

Eval echo "\$$#"

The results are 44.

    

  


The eval command in Linux

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.