Explanation of the usage of the Linux command Eval


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:


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


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:



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

Java atomicinteger class using

A counter For ordinary variables, when multithreading operations are involved, classic thread safety problems will be encountered. Consider the following code: private static final int TEST_THREAD_COUNT = 100; private static int counter = 0; public static void main(String[] args) { final CountDownLatch latch = new CountDownLatch(TEST_THREAD_COUNT); Thread[] threads = new Thread[TEST_THREAD_COUNT]; for (int i = […]