Shell中的“ $$”是什么意思?


Answers:



1

如另一个(可接受的)答案所示,$参数代表当前shell的当前进程ID(PID)。

在大多数shell中(不只是Bash),应使用此参数:

重击:

$ echo $0
bash
$ echo $$
6780

伯恩:

$ echo $0
sh
$ echo $$
6988

C壳:

% echo $shell
/bin/csh
% echo $$
7613

同样重要的是要注意,shell中的命令将在shell的进程ID(PPID)下运行。

$ echo $$
6780
$ ps -ef | grep 6780
aploetz   6780  6770  0 11:15 pts/2    00:00:00 bash
aploetz   8572  6780  0 11:34 pts/2    00:00:00 ps -ef
aploetz   8573  6780  0 11:34 pts/2    00:00:00 grep --color=auto 6780
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.