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.


echo "The process ID of the current shell is: $$"

The process ID of the current shell is: 4181

List of Special Variable that starts with $ and their meaning

$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

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap