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

来源:互联网 发布:手机店刷机软件 编辑:程序博客网 时间:2024/05/16 14:35

参数说明

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

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

3:$$ 表示进程id

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

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

6:$1 表示第一个参数

7:$2 表示第二个参数

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

实验及结果

#!/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



0 0