linux中shell变量$#,$@,$0,$1,$2的含义解释
- 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 QQ
- The complete list is 24249
- The complete list is
- The complete list is 0
- The complete list is 123456 QQ
- The complete list is 123456
- The complete list is QQ
- The complete list is 2
- The complete list is params.sh
- The complete list is 123456
- The complete list is QQ
随机推荐
- C和指针 第十五章 错误报告perror和exit
15.1 错误报告 perror 任何一种程序都存在出错的可能,包括系统的函数库,当出现错误时,系统提示发生错误,标准库函数在一个外部整型变量中保存错误代码,然后把错误代码传给用户程序,提示错误原因. ...
- HTML5存储之 indexedDB
IndexeDB是HTML5 重要的一部分,它是一种轻量级的NOSQL数据库.对创建具有丰富本地存储数据的数据密集型的离线HTML5 Web 应用程序很有用. IndexedDB是为了能够在客户端存储 ...
- python之路十五
CSS position 属性 定义和用法position 属性规定元素的定位类型.说明这个属性定义建立元素布局所用的定位机制.任何元素都可以定位,不过绝对或固定元素会生成一个块级框,而不论该元素本身 ...
- nginx配置返回文本或json
有些时候请求某些接口的时候需要返回指定的文本字符串或者json字符串,如果逻辑非常简单或者干脆是固定的字符串,那么可以使用nginx快速实现,这样就不用编写程序响应请求了,可以减少服务器资源占用并且响 ...
- Sublime 3 如何设置xftp 排除文件夹“bower_components”,“node_modules”
“bower_components”,“node_modules”这个文件夹,作为模块得引用文件,不需要下载本地进行编码,这里得文件非常多,若是不把这个两个文件夹排除掉掉话,通过xftp下载所有文件的 ...
- IIS性能提升
1. 调整IIS 7应用程序池队列长度 由原来的默认1000改为65535. IIS Manager > ApplicationPools > Advanced Settings Queu ...
- ajax 设置同步
这个问题总是碰见,但是又总是记不住怎么拼写,这次直接写出来,长期保存. Ajax请求默认的都是异步的 如果想同步 async设置为false就可以(默认是true) 例如: $.ajax({ ...
- Java异常处理机构(日常笔记)
try{ 需要保护的代码块 }catch(异常类型 实例){ 捕捉到异常时的代码处理块 }[可有0~多个catch语句] finaly{ 不管异常是否发生都要执行的代码块}
- JavaScript跨域提交数据
1.通过jsonp跨域 场景:假设前台有JS方法"crossJS", 1.1发送请求http://www.xxx.com/?callback=crossJS.(创建一个scr ...
- MongoDB 优化器MongoDB Database Profiler(12)
优化器profile 在MySQL 中,慢查询日志是经常作为我们优化数据库的依据,那在MongoDB 中是否有类似的功能呢?答案是肯定的,那就是MongoDB Database Profiler. 1 ...