$0 进程名称
$$ PID
$? 命令执行后的返回状态.0 为执行正确,非 0 为执行错误
$# 位置参数的数量
$* 所有位置参数的内容
位置变量:
$1 $2 $3...
例子:
$?
命令执行后的返回状态 0 为执行正确,非 0 为执行错误
[root@localhost ~]# echo $?
0
[root@localhost ~]# ca /etc/passwd
bash: ca: command not found
[root@localhost ~]# echo $?
127
$0
取当前进程的名称
[root@localhost ~]# vim a.sh
1 #!/bin/bash
2 echo the name of scripts: $0
[root@localhost ~]# bash a.sh //执行
the name of scripts: a.sh
[root@localhost ~]# pgrep tail // pgrep跟关键字
4510
[root@localhost ~]# pidof tail // pidof跟进程名称
4510
[root@localhost ~]# nc -l 9999
[root@localhost ~]# nc 192.168.100.250 9999
$$
取当前进程的PID
[root@localhost ~]# vim a.sh
1 #!/bin/bash
2 echo the name of scripts: $0
3 echo the PID: $$
[root@localhost ~]# bash a.sh
the name of scripts: a.sh
the PID: 5464
位置变量
[root@localhost ~]# vim a.sh
1 #!/bin/bash
2 echo the name of scripts: $0
3 echo the PID: $$
4 echo 你输入的两个数字的和是:$[$1+$2] // $1 $2 位置变量
[root@localhost ~]# bash a.sh 3 5
the name of scripts: a.sh
the PID: 5644
你输入的两个数字的和是:8
$# 位置参数的数量
$* 位置参数的内容
[root@localhost ~]# vim a.sh
1 #!/bin/bash
2 echo the name of scripts: $0
3 echo the PID: $$
4 echo 你输入了$#个参数,他们是:$*
5 echo 你输入的两个数字的和是:$[$1+$2] // $(expr $1 + $2) $`expr $1 + $2`
[root@localhost ~]# bash a.sh 12 15
the name of scripts: a.sh
the PID: 5767
你输入了2个参数,他们是:12 15
你输入的两个数字的和是:27