Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Radu Rădeanu Jul 10 at 18:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

$$ 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
share|improve this answer

$$ 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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.