What is the meaning of $$1 in bash?

I am actually playing with arguments and its happened. I just thought like to see what will happen if I type $$1 and I did it and got something below.

raja@raja-BONEFISH:~$ $$1
19301: command not found

What's that 19301 mean, is it telling something?

Bottom-Line: what does meaning for $$1 in bash.

1

4 Answers

$$ is the PID (process id) of the current process.

$$1 is the above PID followed by the literal string 1.

So it is telling you that your bash is the process with PID 1930.

But... free trick:

show() { eval echo \$$1; }
show PATH
/home/romano/bin:/usr/local/bin:/bin:/usr/bin

(quite convoluted, ain't it?)

More info in TLDP.

2
  • $$ - pid of the current shell (not subshell) - see What are the special dollar sign shell variables?

  • $$1 - pid of the current shell (not subshell) followed by 1.

  • $$2 - pid of the current shell (not subshell) followed by 2.

  • $$a - pid of the current shell (not subshell) followed by a character.

  • And so on...

See the output of echo $$1.

And you get the error command not found because you are trying to execute a string composed of digits which obviously is not a command.

You have concatenated $$ and 1 together to get the PID of the current shell and 1, i.e. $$ stands for the PID of the currently running shell and 1 is just a character, you could do $$a, $$@ to get the PID concatenated with the following character.

$$ it will state 1930 which is pid of current shell .

When you type $$1 that means pid followed by one so you the output would be 19301 .

Try $$2 the output will be 19302

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like