#! /bin/bashpid=$ (pgrep Hello) echo ${pid}
The script name is hello_test.sh
Always returns two values when a hello process exists
When the hello process does not exist, the return value is not empty, always returns a value, runs multiple times, and the returned value is not fixed
Of course, none of the above is the desired result.
Why not exist, also return, and the return value is not the same, remember that there is an internal variable remember the last shell process PID,
That should be the case.
The person reminds, the script is also hello.sh, finally came to realize, the foot name is hello_test.sh, also contains Hello, that return value should be the current script PID
To finish the test, add in the original script
Echo $$
When Hello is not running, it outputs two lines of the same value, which is expected to be proved.
Find a small hidden dessert bar, hehe!
Exception analysis of shell script variable get program output result