Eval in the shell

Source: Internet
Author: User

Eval syntax

Eval arg1 arg2 ...

The function of Eval is to take the following parameters Arg1 Arg2 and so on as a pipeline, and then re-execute the shell process pipeline (about pipeline, see http://www.cnblogs.com/chaoguo1234 /p/5724321.html)

Suppose you have the following script statement:

var="ls | more"$var

The above program is intended to enumerate the files of the current directory, and then use more to show the results, but the actual execution will be error:

Ls:can ' t access |:no Such file or directory

Ls:can ' t access more:no Such file or directory

The reason is that after the command to replace the $var, the shell for Command lookup, at this time to find the command is LS, followed by | And more as the parameters of LS, and the current directory is not named | and more files and directories, so the return error. Take a look at the shell's process of processing the command to clear:

As you can see, the shell performs a command lookup when the $var variable extension is executed.

The way to solve this is to use the eval command:

var="ls | more"eval $var

After the variable substitution of $var is done, it becomes the eval ls | More, and then, according to the syntax of Eval, the shell would have LS | More as a pipeline, start from the first step.

Eval in the 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.