Possible Duplicate:
What does $$ mean in the shell?
I am reading a shell script for Linux and come upon the variable $$
: two dollar signs. Basically the full line is
work_dirname=/tmp/my-work-$$
What does the $$
mean?
Possible Duplicate:
What does $$ mean in the shell?
I am reading a shell script for Linux and come upon the variable $$
: two dollar signs. Basically the full line is
work_dirname=/tmp/my-work-$$
What does the $$
mean?
$$
gives the process ID of the shell.
It is process ID (PID) of the script itself. The
$$
variable often finds use in scripts to construct "unique" temp file names (see Example 32-6, Example 16-31, and Example 15-27). This is usually simpler than invoking mktemp.
(Source: http://tldp.org/LDP/abs/html/internalvariables.html#PROCCID)
It's the process id of the script being executed. This can be used to create a unique file name for temporary files, which is what the script that you're looking is probably doing.
See: http://tldp.org/LDP/abs/html/internalvariables.html#PROCCID
@KingsIndian is right: $$
gives the process ID of the shell.
But what is a process ID?
To understand that, try this:
$ echo $$
$ sh
$ echo $$
$ exit
$ echo $$
The first and third echos print the same process ID, but the middle one prints a different one. The difference is that the sh
command suspends your existing shell and opens a new shell, which is a new process and has its own ID.
Syntax as in your example is used when one wishes each shell to have its own file, which will not conflict against files opened by other shells. Whether this is robust or not depends on what will be done with the file, but it is a strategy one sometimes sees used.
See also the mktemp
command.