1854626 Members
6590 Online
104102 Solutions
New Discussion

what is $$ ?

 
SOLVED
Go to solution
u856100
Frequent Advisor

what is $$ ?

hi people,

no rush with this one!

I'm just curious what the $$ variable is

#> echo $$
24888

some sort of internal sequence number incrementing with each command/login?

thanks in advance

John
chicken or egg first?
7 REPLIES 7
H.Merijn Brand (procura
Honored Contributor
Solution

Re: what is $$ ?

$$ is the current working shell's process ID

# ps -ef | grep $$

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Kyri Pilavakis
Frequent Advisor

Re: what is $$ ?

$$ is the process number of the current shell. This is useful for creating unique temporary work files e.g ls >temp$$
Bosses don't undestand..HP does
Gerhard Roets
Esteemed Contributor

Re: what is $$ ?

Hi John

$$ is the PID of the shell from which it is called. I tend to add the date and maybe time onto it ... but thats just me being paranoid ... but when it is used for lockfiles I can easily find lockfiles prior to the last reboot ... but i'm going of at a tagent :P

Regards
Gerhard
MarkSyder
Honored Contributor

Re: what is $$ ?

$$ is sometimes used to create a backup file (which, I suspect, is the context you've seen it in). E.g. mv logfile logfile.$$

This should be used with caution: if it's not carefully scripted you can end up with two files appended to each other. I've seen it happen with print files. It caused quite a few scratched heads when a new print was accompanied by a print from several weeks earlier.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
u856100
Frequent Advisor

Re: what is $$ ?

thanks people

appreciate all the responses

John
chicken or egg first?
Fred Martin_1
Valued Contributor

Re: what is $$ ?

I also use $$ to create temp files, especially when the program might be run concurrently by several users.

Example:

TMP=/var/tmp/work.$$

If several people run the script at the same time, several temp files will be created and they won't stomp on each other, since each person running the script has their own process ID.
fmartin@applicatorssales.com
Bill Hassell
Honored Contributor

Re: what is $$ ?

$$ is one of many shell internal variables that are quite useful:

$$ current PID of this shell
$# number of parameters on the command line
$? return code from the last process run
$! PID of the last process put into the background
$0 name of the current shell or script
$1 value of the first parameter on the command line
$2 $3 etc values of additional parameters on the command line
$* all the parameters on the command line
$@ basically the same as $* ($@ preferred)


Bill Hassell, sysadmin