Why do I get a number when doing that :
echo $$
which returns
489
If I open a new terminal it returns another number. It seems it's related to the pid of the terminal session, but why ?
Why do I get a number when doing that :
echo $$
which returns
489
If I open a new terminal it returns another number. It seems it's related to the pid of the terminal session, but why ?
$$
means your current PID.
As seen in Bash Reference Manual - 3.4.2 Special Parameters:
$
Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell.
You can test it by doing ps -ef | grep 489
, and it will show the process in which you are logged in.
For example in my case:
$ 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
Because that's how it is defined. $$
is a special shell variable (like e.g. $!
, $_
, $@
, $1
, ...) referring to the PID of the invoked shell.