Kitty Kitty - 11 months ago 43
Bash Question

What does $$ mean in the shell?

I once read that one way to obtain a unique filename in a shell for temp files was to use a double dollar sign (

). This does produce a number that varies from time to time... but if you call it repeatedly, it returns the same number. (The solution is to just use the time.)

I am curious to know what
actually is, and why it would be suggested as a way to generate unique filenames.


In Bash $$ is the process ID, as noted in the comments it is not safe to use as a temp filename for a variety of reasons.

For temporary file names, use the mktemp command.