What is $$ in Bash Shell Script- Special Variable

If you are wondering what $$ (double-dollar) is in a bash shell script, well it is a special variable that can be used to know the Process ID or PID of the current shell.

Let's try running this on a bash shell.

bash_script.sh
#!/bin/bash

echo "The process ID of the current shell is: $$"
Result:
./bash_script.sh 

The process ID of the current shell is: 4181

List of Special Variable that starts with $ and their meaning

CharacterDescription
$Variable expansion
$!Process ID of the most recent background command
$$Process ID of the current shell
$?Exit status of the most recently executed command
$#Number of command-line arguments passed to the script
$*All command-line arguments as a single string (positional parameters)
$@All command-line arguments as separate strings (positional parameters)
$0Name of the script itself (or the shell)
$1, $2, $3, ...Individual command-line arguments (positional parameters)
bash shell $$ example

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!