there is a script I evolved with it, it has line of command like below :

mytemp=`echo ${sourcedir}|awk -F/ '{printf "/%s/tmp",$2}'`/`basename $0`-$1.$$

at the last of the command we see $$ that produces a number. when I use echo $$ in bash I also see a number like bellow:

 #echo $$

what exactly is this number, and what is $$?

  • 1
    It's your current shell pid – cuonglm Jun 23 '16 at 8:47
  • 1
    That question is not completely right about the answer. – amir jj Jun 23 '16 at 11:23

From Advanced Bash-Scripting Guide:

$$ is the process ID (PID) of the script itself.

$BASHPID is the process ID of the current instance of Bash. This is not the same as the $$ variable, but it often gives the same result.

|improve this answer|||||

$$ is the process ID of the current shell instance. So in your case the number, 23019, is the PID of that instance of bash.

The following should give you a better idea:

ps -p $$
|improve this answer|||||
  • It often finds use in scripts to construct "unique" temp file names. – chaos Jun 23 '16 at 8:48
  • 7
    @chaos Those scripts should use mktemp. – Kusalananda Jun 23 '16 at 8:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.