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