What does $$ mean in the shell?

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.


$$ is the process ID (PID) in bash. Using $$ is a bad idea, because it will usually create a race condition, and allow your shell-script to be subverted by an attacker. See, for example, all these people who created insecure temporary files and had to issue security advisories.

Instead, use mktemp. The Linux man page for mktemp is excellent. Here's some example code from it:

tempfoo=`basename $0`
TMPFILE=`mktemp -t ${tempfoo}` || exit 1
echo "program output" >> $TMPFILE