读书人

shell 非一般变量

发布时间: 2012-06-28 15:20:03 作者: rapoo

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获得运行目录

读书人网 >操作系统

热点推荐