h1

Shell Tips 10: The $$ Trick

February 14, 2011

The $$ temporary file trick. Writing files to /tmp has the disadvantage that it is
shared between all users and processes, leading to possuble clashed, overwrites etc.
$$ is an automatic shell variable containing the ID of the current process. If
a script creats temporary files which have its own name and process ID, the
resulting names will be highly unique. If the script is invoked more than
once, the PIDs will be different and so will the temp file names. This
is true even if it is being run simultaneously by different users or the same user.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: