变量说明:
$$
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 ~]$ bashparams.sh 123456 QQ
The complete listis24249
The complete listis
The complete listis0
The complete listis123456 QQ
The complete listis123456
The complete listisQQ
The complete listis2
The complete listisparams.sh
The complete listis123456
The complete listisQQ
linux中shell变量$#,$@,$*,$?,$$,$!,$_,$0,$1,$2的含义解释
推荐阅读
- 简单的无缝滚动
- Java 操作Word书签(二):添加文本、图片、表格到书签内容
- Navicat Premium 12安装激活教程_不需要激活工具直接激活
- Linux for CentOS 下的 keepalived 安装与卸载以及相关命令操作之详细教程
- Linux for CentOS 下的 nginx 绿色安装-超省心安装
- windows server2012R2 上 .net core IIS 部署--应用程序池 自动停止
- CentOS Linux release 7.7.1908 (Core)--redis安装
- 图片文件分布式存储方案设计模式(c#--sqlserver)
- mybatis-plus多表联合分页查询
- Vue父子组件传值,使用watch监听值变化