Skip to content
The Bash Insectarium

/static/insetario/en/inseto/pid-shell/

Menu

BSH-021 · Ghost variables

$$

The shell's own process number — the session's registration.

Every shell carries its PID in $$. The traditional use is naming temporary files — /tmp/coleta.$$ — with a name that does not collide across sessions.

Colony detail: in a subshell, $$ remains the parent shell's PID; the subshell's own lives in $BASHPID. And for real temporaries, mktemp is the safer neighbor.

$ echo $$
31415
$ touch /tmp/coleta.$$
$ ls /tmp/coleta.*
/tmp/coleta.31415
The session's registration, stamped on a file.