Shell Special variables: Shell $0, $#, $*, [email protected], $?, $$ and command line arguments special variable list variable meaning $0the file name of the current script $n the arguments passed to the script or function. N is a number that represents the first few parameters. For example, the first argument is a $1, the second argument is a $2. $# the number of arguments passed to the script or function. $*all parameters passed to the script or function. [email protected] All parameters passed to the script or function. Surrounded by double quotes (" ") when included, with $*slightly different, as will be mentioned below. $? The exit state of the last command, or the return value of the function. In general, the success of most command execution will return0, failed to return1. $$ the current shell process ID. For Shell scripts, this is the process ID where the scripts are located. $*and [email protected] the difference $* and [email protected] are all arguments passed to the function or script, not double quotes (" ") is included in the" $" " $"..."$n"all parameters in the form of output. But when they are double-quoted (" ") is included,"$*"All parameters will be used as a whole to"$ $ ... $n"All parameters in the form of output;"[email protected]"Each parameter is separated to" $" " $"..."$n"all parameters in the form of output. The following example can be clearly seen in the $*and [email protected] The difference: #!/bin/BashEcho "\$*="$*Echo "\"\$*\"=" "$*"Echo "\[email protected]="[email protected]Echo "\ "\[email protected]\" =" "[email protected]"Echo "print each param from \$*" forVarinch$* Do Echo "$var" DoneEcho "print each param from \[email protected]" forVarinch[email protected] Do Echo "$var" DoneEcho "print each param from \ "\$*\"" forVarinch "$*" Do Echo "$var" DoneEcho "print each param from \ "\[email protected]\"" forVarinch "[email protected]" Do Echo "$var" Doneexecution./test.SH "a" "b" "C" "D"and see the following result: $*=a b c D"$*"=a B C d[email protected]=a b c D"[email protected]"=a b c dprint each param from $*abcdprint each param from [email protected]abcdprint to Param from"$*"a b c dprint each param from"[email protected]"ABCD Note: When double quotes are included,"$*"The parameters are treated as a whole, and"[email protected]"or traverse each parameter
Shell Special variables: Shell $, $#, $*, [email protected], $?, $$ and command line arguments