12345678 |
$# is the number of arguments passed to the script $ 0 is the name of the script itself $ 1 $ 2 [email protected] is a list of all parameters passed to the script $* is to display all parameters passed to the script in a single string, unlike positional variables, which can exceed 9 $$ is the current process ID number for the script to run $? is the exit state that displays the last command, 0 |
Difference:@@*
- Same point: All parameters are referenced
- Different points: only in double quotes. Suppose that three parameters were written when the script was run (stored in1123) then " 3) "*" is equivalent to "1123"(Mass transferHandedThe one Ginseng number ) ;" 3 "(pass a parameter), and" @ "is equivalent to"1""1 "" 2 "" $ $ "(three parameters passed)
Example One
# #dels. Sh
echo "number:$#" echo "Scname:$0" echo "First:" echo "Second:$2" echo "Argume:[email protected]" echo "Show Parm list:$*" echo "Show process id:$$" echo "Show Precomm stat: $?"
Execution results
123456789 |
[@jihite]$ sh del.sh
1
2
3
number:
3
scname:del.sh
first:
1
second:
2
argume:
1
2
3
show
parm list:
1 2
3
show
process id:
21057
show
precomm stat:
0
|
Example Two
#!/bin/shnum=$ #name =$0echo "number: $num" echo "Scname: $name" echo $0echo $1echo $2for ((i=0; i< $num; i++)) do Echo "$i" Doneecho "Argume:[email protected" "for key in [email Protected]do echo $keydoneecho"-----------------"for key In "[email protected]" does echo $keydoneecho "-----------------------------" for Key2 in $*do echo $key 2doneecho " -----------------"for Key2 in" $* "Do echo $key 2doneecho" show process id:$$ "Choecho" show Precomm stat: $? "
Execution results
12345678910111213141516171819202122 |
[@jihite]$ sh del.sh a b
number:
2
scname:del.sh
del.sh
a
b
0
1
argume:a b
a
b
-----------------
a
b
-----------------------------
a
b
-----------------
a b
show
process id:
23582
del.sh: line
37:
cho: command not found
show
precomm stat:
127
|
Problem:
echo #0 #1 can you use $i to express it?
Meaning of variable #,#,@,0,0,1,2,2,*,$$,$ in Linux