Explanation of the usage of the Linux command Eval

Time:2019-9-9

1. eval command-line

Where command-line is a common command line typed on the terminal. When Eval is placed in front of it, however, the result is that the shell scans it twice before executing the command line. Such as:

pipe=”|”

eval ls $pipe wc -l

When the shell scans the command line for the first time, it replaces the value of pipe, and eval makes it scan the command line again, when the shell uses as a pipe symbol.

If the variable contains any characters that require the shell to see directly on the command line (not as a result of replacement), you can use eval. Command-line terminators (;&), I/o redirectors (< >) and quotation marks are symbols of special significance to the shell and must appear directly on the command line.

2. Eval echo \$$# Gets the last parameter

For example: cat last

eval echo \$$#

./last one two three four

four

After the first scan, the shell removed the backslash. When the shell scans the line again, it replaces the value of $4 and executes the echo command

3. The following shows how to create a pointer to a variable with the Eval command:

x=100

ptrx=x

Eval echo\$$ptrx points to ptrx, and you can understand the example in B in this way.

100 Print 100

Eval $ptrx = 50 stores 50 in a variable pointed to by ptrx.

echo $x

50 Print 50

Recommended Today

Write a package for parsing abnormal JSON strings – fbbk-json

F [beep] [beep] K JSON Parse a package of abnormal JSON strings. install $ npm install fbbk-json Use This package has only one function: var fJSON = require(“fbbk-json”); fJSON.parse(A_JSON_STRING); however This package supports the following JSON strings (that is, what we usually declare in javascript, without quotation marks). Raise a chestnut. ‘{foo”:”bar”,”baz”: true} < – […]