Shell eval usage

Source: Internet
Author: User
Tags echo command

1. Eval command-line

Command-new Roman; "> line is a common command line typed on the terminal.HoweverEvalThe result is shell.Scan it twice before executing the command line.For example:

New Roman; "> pipe =" |"

New Roman; "> eval ls $ pipe WC-l

New Roman; "> shell replaces the pipe value when scanning command lines for 1st times. | then, Eval enables it to scan command lines again. Then, shell uses | as the pipe symbol.

If the variable contains any shellYou can use the eval command to directly view the characters (not the replacement result) in the command line.. Command line terminator (;| &), I/New Roman; "> ORedirection character (<>) And quotation marks belong to the shellSymbols of special significance must appear in the command line directly.

2. Eval echo/$ #Get the last parameter

For example, cat last

New Roman; "> eval echo/$ #

New Roman; ">./last one two three four

New Roman; "> four

After the first scan, shell removes the backslash. When shell scans the row again, it replaces the value of $4 and runs the echo command.

3.How to UseEvalCommand to create a pointer to the variable ":

New Roman; "> x= 100

New Roman; "> ptrx = x

New Roman; "> eval echo/$ ptrx points to ptrx. Here we can understand the example in B.

New Roman; "> 100 print 100

New Roman; "> eval $ ptrx = 50: save 50 to the new Roman;"> variable pointed to by ptrx.

New Roman; "> echo $ x

New Roman; "> 50 print 50

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.