shell 特殊变量

本文详细介绍Shell脚本中特殊变量的功能及用法,如$0获取脚本名称,$*获取所有参数等。通过实例帮助理解每个变量的作用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[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获得运行目录
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值