What Does "$$" Mean in Shell?

In a shell, $$ refers to the process id (PID) of the current running process. For example, when used inside a shell script, it would return the process id of the running script. Similarly, when used inside a terminal (e.g. echo $$), it would return the process id of the current shell (as the current running process in that case would be the shell itself). One common use of $$ is to check which shell is being used in terminal.

Using $$ is not considered a good way to generate unique filenames, and should be avoided for such tasks wherever possible because it can lead to vulnerabilities in your shell scripts.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.