$# 是传给脚本的参数个数 $ 0 是脚本本身的名字 $ 1 是传递给该shell脚本的第一个参数 $ 2 是传递给该shell脚本的第二个参数 [email protected] 是传给脚本的所有参数的列表 $* 是以一个单字符串显示所有向脚本传递的参数,与位置变量不同,参数可超过 9 个 $$ 是脚本运行的当前进程ID号 $? 是显示最后命令的退出状态, 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