为什么echo $$返回数字? [英] Why does echo $$ return a number?

查看:67
本文介绍了为什么echo $$返回数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这样做时会得到一个数字:

Why do I get a number when doing that :

echo $$

返回

489

如果我打开一个新终端,它将返回另一个数字。似乎与终端会话的pid有关,但是为什么呢?

If I open a new terminal it returns another number. It seems it's related to the pid of the terminal session, but why ?

推荐答案

$$ 表示您当前的PID。

$$ means your current PID.

Bash参考中所示手册-3.4.2特殊参数


$

$

扩展为Shell的进程ID。在()子外壳中,它将
扩展为调用外壳程序的进程ID,而不是子外壳。

Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell.

通过执行 ps -ef |进行测试grep 489 ,它将显示您登录的过程。

You can test it by doing ps -ef | grep 489, and it will show the process in which you are logged in.

例如,在我的情况下:

$ echo $$
3470

$ ps -ef | grep 3470
1000      3470  3469  0 10:59 pts/3    00:00:00 -bash    <---- this process
1000      8151  3470  0 15:37 pts/3    00:00:00 ps -ef
1000      8152  3470  0 15:37 pts/3    00:00:00 grep --color=auto 3470

这篇关于为什么echo $$返回数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆