$0 这个程式的执行名字 $n 这个程式的第n个参数值,n=1..9 $* 这个程式的所有参数,此选项参数可超过9个。 $# 这个程式的参数个数 $$ 这个程式的PID(脚本运行的当前号) $! 执行上一个背景指令的PID(后台运行的最后一个进程的号) $? 执行上一个指令的返回值 (显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误) $- 显示shell使用的当前选项,与set命令功能相同 $@ 跟$*类似,但是可以当作数组用 linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 所有参数列表。此选项参数可超过9个,以"$1 $2 … $n"的形式输出所有参数。 $@ 所有参数列表。跟$*类似,但是可以当作数组用、以"$1" "$2" … "$n" 的形式输出所有参数。 $# 添加Shell命令后边的参数个数 ,if [ $# -ne 1 ]; then echo "shell后边的参数不是1个" $0 Shell本身的文件名 $1~$n 添加到Shell的各参数值。$1是第1参数、$2是第2参数…。 这里参考:
示例:
1 #!/bin/bash 2 # 3 printf "The complete list is %s\n" "$$" 4 printf "The complete list is %s\n" "$!" 5 printf "The complete list is %s\n" "$?" 6 printf "The complete list is %s\n" "$*" 7 printf "The complete list is %s\n" "$@" 8 printf "The complete list is %s\n" "$#" 9 printf "The complete list is %s\n" "$0"10 printf "The complete list is %s\n" "$1"11 printf "The complete list is %s\n" "$2 |
结果:
[Aric@localhost ~]$ bash params.sh 123456 QQThe complete list is 24249The complete list isThe complete list is 0The complete list is 123456 QQThe complete list is 123456The complete list is QQThe complete list is 2The complete list is params.shThe complete list is 123456The complete list is QQ |
Have a nice day!!!
本文出自 “梅花香自苦寒来!” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1844698
原文地址:http://daixuan.blog.51cto.com/5426657/1844698