3

The output of echo $$ command displays some number in the standard output like below.

$ echo $$
14594

What is that number? And also,

$ x=a
$ echo $x
a

In the above example echo $x parses the variable x and displays the value of x to the standard output.Likewise in this command echo $$, is that the second dollar symbol represents any variable?

0

2 Answers 2

3

$$ is the PID (process identifier) of the current shell (not subshell). Within a script, inside a subshell, $$ returns the PID of the script, not the subshell. See Internal Variables.

You can find also the PID returned by echo $$ in terminal in the output of the following command:

ps ax | grep bash
2

$$ is one of bash's internal variables. Unlike $x, in your example, it does not "contain" a value, the value is requested each time accessing the variable.

In a bash script, it returns the process id of the script itself. In a script you can call kill $$ to send SIGTERM to your script.

In a bash shell, it returns the process id of the currently running bash process.

In a bash script, inside a subshell, it returns the process id of the script, not the subshell.

Not the answer you're looking for? Browse other questions tagged .