shell $参数说明
2012-10-11 11:44
218 查看
[root@server ~]# cat test.sh
#!/bin/bash
printf "\$$ Shell本身的PID(ProcessID) is %s\n" "$$"
printf "\$! Shell最后运行的后台Process的PID is %s\n" "$!"
printf "\$? 最后运行的命令的结束代码(返回值) is %s\n" "$?"
printf "\$*||\$@ 所有参数列表 is %s\n" "$*"
printf "\$# 添加到Shell的参数个数 is %s\n" "$#"
printf "\$0 Shell本身的文件名 is %s\n" "$0"
printf "\$1~\$n 添加到Shell的各参数值。$1是第1参数、$2是第2参数… is %s\n" "$1"
printf "\$1~\$n 添加到Shell的各参数值。$1是第1参数、$2是第2参数… is %s\n" "$2"
[root@server ~]# ./test.sh 2 3 4 5
$$ Shell本身的PID(ProcessID) is 3879
$! Shell最后运行的后台Process的PID is
$? 最后运行的命令的结束代码(返回值) is 0
$*||$@ 所有参数列表 is 2 3 4 5
$# 添加到Shell的参数个数 is 4
$0 Shell本身的文件名 is ./test.sh
$1~$n 添加到Shell的各参数值。2是第1参数、3是第2参数… is 2
$1~$n 添加到Shell的各参数值。2是第1参数、3是第2参数… is 3
$#测试
[root@server ~]# cat 1.sh
#!/bin/bash
if [ $# = 1 ]
then
echo "1"
else
echo "2"
fi
[root@server ~]# ./1.sh 1
1
[root@server ~]# ./1.sh 1 2
2
[root@server ~]# ./1.sh 1 2 3
2
#!/bin/bash
printf "\$$ Shell本身的PID(ProcessID) is %s\n" "$$"
printf "\$! Shell最后运行的后台Process的PID is %s\n" "$!"
printf "\$? 最后运行的命令的结束代码(返回值) is %s\n" "$?"
printf "\$*||\$@ 所有参数列表 is %s\n" "$*"
printf "\$# 添加到Shell的参数个数 is %s\n" "$#"
printf "\$0 Shell本身的文件名 is %s\n" "$0"
printf "\$1~\$n 添加到Shell的各参数值。$1是第1参数、$2是第2参数… is %s\n" "$1"
printf "\$1~\$n 添加到Shell的各参数值。$1是第1参数、$2是第2参数… is %s\n" "$2"
[root@server ~]# ./test.sh 2 3 4 5
$$ Shell本身的PID(ProcessID) is 3879
$! Shell最后运行的后台Process的PID is
$? 最后运行的命令的结束代码(返回值) is 0
$*||$@ 所有参数列表 is 2 3 4 5
$# 添加到Shell的参数个数 is 4
$0 Shell本身的文件名 is ./test.sh
$1~$n 添加到Shell的各参数值。2是第1参数、3是第2参数… is 2
$1~$n 添加到Shell的各参数值。2是第1参数、3是第2参数… is 3
$#测试
[root@server ~]# cat 1.sh
#!/bin/bash
if [ $# = 1 ]
then
echo "1"
else
echo "2"
fi
[root@server ~]# ./1.sh 1
1
[root@server ~]# ./1.sh 1 2
2
[root@server ~]# ./1.sh 1 2 3
2
相关文章推荐
- shell简介之bash编程之参数说明
- shell if 命令参数说明
- bash shell if 命令参数说明
- shell的ps命令参数列表解释说明
- shell if 命令参数说明
- shell下数字和字符串比较操作命令 if的参数说明
- shell的ps命令参数列表解释说明
- shell if 命令参数说明
- shell中if的参数说明
- Shell 脚本参数说明
- bash shell if 命令参数说明
- bash shell if 命令参数说明
- shell脚本程序中的部分常用环境变量和参数变量的说明以及简单shell脚本示例
- shell的ps命令参数列表解释说明
- shell if语句的参数说明
- shell -e -d等参数说明
- bash shell if 命令参数说明
- adb shell ip命令参数说明
- Shell基础篇---shell简介之bash编程之参数说明
- bash shell if 命令参数说明