Positional variables:
$: Gets the file name of the current execution shell, including the script path if the script is executed with a path
$n: Gets the n=1..9 parameter value of the currently executing shell script, which represents the file name of the script when n is 0, and if n is greater than 9, the curly braces are enclosed in ${10}.
[email protected] ~]# vim q.sh
echo $ $4 $ $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14} ${15}
Results of the output
[email protected] ~]# sh q.sh {a.. Z
A b c d e F g h i j k l m n o
$*: Treats all command-line parameters as a single string, equivalent to "$1$2$3", "$*"
[email protected]: Treat each parameter of the command line as a separate string, equivalent to "$!" $ "$" This is the best way to pass parameters to other programs because he retains any whitespace embedded in each parameter
Note : The above differences are limited to double quotes, i.e. "$*" and "[email protected]"
Example:[[email protected] ~]# Set--"I am" from Hunan
[email protected] ~]# echo $#
3
Example :
[[email protected]~]# for I in "$*";d o echo $i;d one with double quotes, as a parameter output
I am from Hunan
[[email protected]~]# for i in "[email protected]";d o echo $i;d one with double quotes, independent output
I am
From
Hunan
Example:
[[email protected] ~]# for I;do Echo $i;d One removes the in variable list, equivalent in "[email protected]"
I am
From
Hunan
Example:
[[email protected] ~]# for i in $*;d o echo $i;d one without double quotes, all parameters are output, and the first parameter "I Am" is also opened
I
Am
From
Hunan
$?: Gets the return value that executes the last instruction (0 is successful, nonzero is failed) This variable is very common.
Cases:
echo $?
$#: Gets the total number of parameters after the currently executing shell script.
Enterprise Case Control the number of user parameters :
[ [email protected] ~]# vim q1.sh
[$#-ne 2] && {
echo "Pls input number"
Exit 1----> assigns a value to the current shell's $? variable.
}
echo "Thanks!"
Note-shell Special variables