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: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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