linux中shell变量$#,$@,$0,$1,$2的含义解释(转)
| 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 $* 所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 $@ 所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。 $# 添加到Shell的参数个数 $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 |
随机推荐
- NET Core1.0之CentOS平台开发控制台程序DEMO
微软发布NET Core1.0正式版本,并支持了red hat linux平台,所以在CentOS平台,通过编辑器玩下控制器程序. 一.安装.NET Core SDK 先下载SDK并放在指定目录. s ...
- const的位置与区别
转自 http://www.cnblogs.com/wucx/p/4566176.html 一个比较经典的问题——问以下两种声明的区别:1) const char * p2) char * co ...
- mysql - 其它
1.mysql查看表字段和字段描述 SELECT column_name, column_comment FROM information_schema.columns WHERE table_sch ...
- 右键添加"用vim打开"文件选项
保存一个foo.reg文件 ==================== Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\Shell\e ...
- &&和||的妙用
在js逻辑运算中,0."".null.false.undefined.NaN都会判为false,其他都为true 几乎所有语言中||和&&都遵循“短路”原理,如&a ...
- 编程风格(Coding Style)要求
编程风格(Coding Style)要求2.1.1 文件(1) 每个模块(module)一般应存在于单独的源文件中,通常源文件名与所包含模块名相同.(2) 每个设计文件开头应包含如下注释内容:? 年份 ...
- UML类图画法及其之间的几种关系(转)
UML类图画法及其之间的几种关系 最近做重构项目,需要画一下类图,发现类图的画法及其之间的几种关系已经淡忘了很多,所以整理总结一下,有问题的地方大家可以一起讨论下. 文章目录如下: 类图画法 类之间的 ...
- cookie小记
清除cookie可用下面2种的方法.注意如果要清除的cookie的域是指定的,则这里也应该指定,否则无效 1: Response.Cooki ...
- ef 对象无法序列化的问题(System.Data.Entity.DynamicProxies)
错误提示: System.InvalidOperationException: 生成 XML 文档时出错. ---> System.InvalidOperationException: 不应是类 ...
- CURL详解(转载)
curl_setop()函数中的参数中文说明 curl_setop()函数中的参数中文说明 curl_setopt()函数将为一个CURL会话设置选项.option参数是你想要的设置,value是这个 ...