shell脚本变量$#,$*,$$,$@,$0,$1,$2,$?的含义

参数说明

1:$# 表示执行脚本传入参数的个数

2:$*  表示执行脚本传入参数列表

3:$$ 表示进程id

4:$@表示执行脚本传入所有参数

5:$0 表示执行脚本名称

6:$1 表示第一个参数

7:$2 表示第二个参数

8:$? 表示脚本执行状态0正常,其他表示有错误

实验及结果(shellTest.sh)

#!/bin/sh

echo "parm number is : $#"
echo "parm list   is : $*"
echo "all parm is : $@"
echo "process is : $$"
echo "file name is : $0"
echo "the first parm is : $1"
echo "stat is : $?"

执行及结果

执行:sh shellTest.sh "the first parm " "the second parm"

parm number is : 2
parm list   is : the first parm  the second parm
all parm is : the first parm  the second parm
process is : 28669
file name is : shellTest.sh
the first parm is : the first parm 
stat is : 0

转载:https://blog.csdn.net/kejiaming/article/details/51859503

猜你喜欢

转载自www.cnblogs.com/xulan0922/p/9258914.html