您的位置:首页 > 运维架构 > Shell

shell脚本的特殊变量

2016-10-15 15:00 465 查看
1. 单个参数 $1、$2 ......

oliver@bigdatadev:~$ more demo.sh
#!/bin/sh
echo The First argument: $1
echo The Second argument: $2
echo The Third argument: $3
oliver@bigdatadev:~$ demo.sh 10 20 30
The First argument: 10
The Second argument: 20
The Third argument: 30
oliver@bigdatadev:~$

2. 脚本名 $0

3. 参数的数量 $#
4. 所以参数 $@

5.进程号 $$

6.退出码 $?

oliver@bigdatadev:~$ more demo2.sh
#!/bin/sh
echo File Name: $0
echo PID: $$
echo Argument Count: $#
echo Artuments: $@
exit 100
oliver@bigdatadev:~$ demo2.sh 10 20 30
File Name: ./demo2.sh
PID: 3182
Argument Count: 3
Artuments: 10 20 30
oliver@bigdatadev:~$ echo $?
100
oliver@bigdatadev:~$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: