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 |
随机推荐
- 微软要支持Objective-C了
今天的新闻,见http://www.solidot.org/story?sid=43899 更详细的见,http://arstechnica.com/information-technology/20 ...
- 在table中进行内容搜索
$("tbody td").filter(":contains('" + x + "')").css('color','red').pare ...
- Tomcat 设置
bin/catalina.bat--增加内存 set JAVA_OPTS=...后面加上 set JAVA_OPTS=-Xmx1024M -Xms512M -XX:MaxPermSize=256m c ...
- LAMP之准备,samba搭建
搭建lamp其实并没有多复杂,只是,最多的时间是花在下载等待和计算机编译等上面耗时,要是时间多花在这些事情上面总感觉有点亏.经过我多次实践,发现在linux下使用下载会有诸多问题,甚至不如window ...
- modelsim 中 WAVE窗口中能不能只显示变量名,而不显示路径
可以的,在wave窗口左下角有一个黑色的logo,你点击它就可以省电路径,只显示port名称,再点击就切换回来了,如图红色圈圈标记的logo,你可以试试!
- 从H264码流中获取视频宽高 (SPS帧)
获取.h264视频宽高的方法 花了2个通宵终于搞定.(后面附上完整代码) http://write.blog.csdn.net/postedit/7852406 图像的高和宽在H264的SPS帧中.在 ...
- 关于 cellForRor中给cell setSelected的时机问题?
我在 cell 里边 - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selecte ...
- 轻型的ORM类Dapper
Dapper是一个轻型的ORM类.代码就一个SqlMapper.cs文件,主要是IDbConnection的扩展方法,编译后就40K的一个很小的dll.官方站点http://code.google.c ...
- 第二章 centos安装maven
一.官网下载 apache-maven-3.3.9-bin.tar.gz 注意:需要jdk1.7及以上 二.上传 scp apache-maven-3.3.9-bin.tar.gz root@10.2 ...
- NGUI 使用EventDelegate.Add与UIInput.onSubmit、UIInput.onChange限定编辑框中的内容
Unity中,使用NGUI,通常为某个控件(如按钮)绑定事件(单击.双击.拖拽.滚轮.选择等)都是用UIEventListener,比如: public void Bind() { UIEventLi ...