Shell 特殊变量
特殊变量
$$
当前 shell 的进程ID
1 |
|
输出当前进程的pid
1 |
|
$0 | 当前脚本的文件名 |
---|---|
$n | 当前脚本的参数,从1开始 $1 第一个参数,$2 第二个参数,$n 第n个参数 |
$# | 脚本参数的总个数 |
$* | 脚本参数集合,所有的参数被双引号包裹。如果脚本2个参数,$* ="$1 $2" |
$@ | 脚本参数集合,每个参数被单独的双引号包裹。如果脚本2个参数,$* ="$1" "$2" |
$? | 上个命令的返回值。 |
$$ | 当前shell 的进程ID。 |
$! | The process number of the last background command. |
示例
1 |
|
输出
1 |
|
$*
和$@
the $*
special parameter takes the entire list as one argument with spaces between and the $@
special parameter takes the entire list and separates it into separate arguments.
1 |
|
输出
1 |
|
$?
检查上个命令是否执行成功。
1 |
|
Shell 特殊变量
https://yxibng.github.io/2022/02/25/Shell/2022-02-25-shell 特殊变量/