shell 特殊变量

[linest@036194.sqa.cm4]$ sh test.sh a b c d e
$0 return shell name
test.sh
$n return nth parameter
c
$* return all parameters
a b c d e
$# return the number of parameters
5
$$ return current shell pid
32202
$! return last command pid
32203
$? return last command return value(0 success other fail)
0
$@ return all the parameters
a b c d e
$@ treat each parameter individually  $* treat all parameters as a whole string
[linest@036194.sqa.cm4]$


$0 返回脚本名称,但如果运行时含路径,也显示路径信息
${0%/*}可以获得脚本所在的目录
不同于pwd获得运行目录

你可能感兴趣的:(shell)