Process state variables
1, $$ get the current shell process number (PID)
2, $! executes the PID of the previous instruction
3, $? Gets the return value that executes the previous command (0 is a success, Non-zero is a failure, this is very common)
4. $_ the last parameter of a command or script executed before this
Copy Code code as follows:
Cat> test$.sh
Echo ' $$= ' $$
Echo ' $!= ' $!
Echo ' $?= ' $?
Echo ' $@= ' $@
Echo ' $_= ' $_
#输出如下
SH test\$.sh 1 2 3
$$=2556
$!=
$?=0
$@=1 2 3
The difference between $* and $@
$* treats all parameters as a single string, equivalent to "$1$2$3"
$@ treats each parameter as a single string, preserving any whitespace characters in the command line
Copy Code code as follows:
set--' I am ' Jane Lee
Fori in$*; doecho$i; Done
I
Am
Jane
Lee
Fori in$@; doecho$i; Done
I
Am
Jane
Lee
Fori in "$@"; doecho$i; Done
I am
Jane
Lee
Fori in "$*"; doecho$i; Done
I am Jane Lee