$0, $? , $! The significance of etc.

Variable declaration

PID (ProcessID) $! PID $? End code of the last command run (return value) $- A list of all parameters $* Set with the Flag command. Such as"$*"With""(").The $1 $2$n"To print all parameters in the form.$@All parameter lists. Such as"$@"With" "", in order to"The $1" "$2""$n"Output all parameters in the form of.$#Number of arguments added to the Shell$0The file name of the Shell itselfThe $1~$nParameter values added to the Shell.The $1Is the first parameter,$2Is the second argument... .Copy the code

Script Examples We write a simple script first, and then explain the meaning of each variable after executing it

# touch variable
# vi variableThe script content is as follows:#! /bin/sh
echo "number:$#"
echo "scname:$0"
echo "first :The $1"
echo "second:$2"
echo "argume:$@"Save and exit to grant the script execution permission# chmod +x variable   Execute the script# ./variable aa bb
number:2
scname:./variable
first: aa
second:bb
argume:aa bb
Copy the code

Results analysis

As you can see from the result: $# is the number of arguments passed to the script. $0 is the name of the script itselfCopy the code