Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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

$ echo $$

What is that number? And also,

$ x=a
$ echo $x

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 command-line Jul 10 '14 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.

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