Ways to create a temp file:

Using mktemp:

$ mktemp /tmp/file.XXX

The trailing Xs will be replaced with the process number and/or a unique letter combination

Creating a temp dir:

$ mktemp -d /tmp/dir.XXX

Output could be saved into a variable:

TMPDIR=$(mktemp -d /tmp/dir.XXXX)


Using $$:


Here $$ will be replaced with the current process PID.



$RANDOM is an internal bash/zsh function (not a constant) that returns a pseudorandom [1] integer in the range 0 - 32767