1745786 Members
3568 Online
108722 Solutions
New Discussion юеВ

Re: What is the $$ for?

 
SOLVED
Go to solution
SM_3
Super Advisor

What is the $$ for?

If I had a file in a script like the following

LOG=/tmp/log-trimmer.$$

what does the $$ stand for??

thanks
8 REPLIES 8
SM_3
Super Advisor

Re: What is the $$ for?

I found this...

$$ - process number of current process

can someone elaborate.

thanks
G. Vrijhoeven
Honored Contributor

Re: What is the $$ for?

The $$ stands for the currert PID ( a number)

Regards,

Gideon
Simon Hargrave
Honored Contributor
Solution

Re: What is the $$ for?

The $$ is substituted by the shell to be the current process ID.

It's use in this case is to ensure that the script has a unique filename.

eg if you run that script twice, one may use filename log-trimmer.4457, and the other log-trimmer.4459, therefore they won't conflict with each others files.
Jose Mosquera
Honored Contributor

Re: What is the $$ for?

Hi,

This is your current process id
#echo $$
28722

In this case must correspond at your telnet session shell ID:
#ps
PID TTY TIME COMMAND
28722 pts/tp 0:00 sh
28721 pts/tp 0:00 telnetd
25808 pts/tp 0:00 ps

Rgds
John Poff
Honored Contributor

Re: What is the $$ for?

Hi,

As mentioned it gives the current PID. It is often used in shell scripts to create a unique temporary file name. To be safe there should be a line just before that which removes that filename, which prevents the script from using an existing file which could be left over from a previous run of the script, or could be planted by a malicious user or script.

JP
G. Vrijhoeven
Honored Contributor

Re: What is the $$ for?

A process is identified by a number. This number is called the PID ( process ID) A process also has a perant id ( PPID) that is the process number from wich the process is spawned.
This number can be used by e.g kill to terminate the process.

Regards,

Gideon

A. Clay Stephenson
Acclaimed Contributor

Re: What is the $$ for?

$$ or more betterer ${$} is the PID (Process ID Number). The goal in your case was to create a unique file name although since PID's rollover a bit more testing is really needed to make sure that the file does not already exist.
If it ain't broke, I can fix that.
Rory R Hammond
Trusted Contributor

Re: What is the $$ for?

Clay,
makes a good point about "uniq" files.
${$} works most of the time.

LOG=/tmp/log-trimmer.$$
could be rewritten as:

log=$(mktemp -d /tmp -p log-trimmer)

rory

There are a 100 ways to do things and 97 of them are right