LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   $$$ in command line (https://www.linuxquestions.org/questions/linux-newbie-8/%24%24%24-in-command-line-4175448264/)

BobShumaker 02-01-2013 07:49 PM

$$$ in command line
 
When I enter (echo "I would like lots of $$$") without the parentheses - the number that is displayed in the response is supposed to represent what value?

allend 02-01-2013 08:10 PM

From 'man bash'
Quote:

$ Expands to the process ID of the shell.
i.e. The second $ in 'echo "I would like lots of $$$"' is interpreted to the number of the process ID of the shell.

shivaa 02-01-2013 08:38 PM

$$ points to process-id of currently running process i.e. shell.

Let's say if you have login into some system using ssh, and entered into a new shell. Then you can find process-id of that process as,
Code:

~$ ps -ef | grep ssh
OR
~$ pgrep ssh

So then:
Code:

~$ echo $$
Will show you the process-id of currently running shell process i.e. process-id of your running ssh session (i.e. process).

Use of more $ characters will do nothing, but just repeatedly print the process-ids again and again. For instance:
Code:

~$ echo This is $$
This is 1234
~$ echo This is $$$
This is 1234$
~$ This is $$$$
This is 12341234

So, in a nutshell, shell considers use of $$ as process-id of currently running process, and $ as simple character.

Habitual 02-02-2013 10:55 AM

Quote:

Originally Posted by shivaa (Post 4882738)
$$ points to process-id of currently running process i.e. shell.

yeah, about that...

I recently went round and round with "$$" and "$0" and concluded
"While the shell or process is running, $0 holds the numerical value of the process ID"
"While the shell or process is running, $$ holds the string value of the process name"

bash, of course. :)

Or is my logic incorrect?

suicidaleggroll 02-02-2013 11:06 AM

Quote:

Originally Posted by Habitual (Post 4883076)
yeah, about that...

I recently went round and round with "$$" and "$0" and concluded
"While the shell or process is running, $0 holds the numerical value of the process ID"
"While the shell or process is running, $$ holds the string value of the process name"

bash, of course. :)

Or is my logic incorrect?

I think you have that backward
Code:

> echo $0
/bin/bash
> echo $$
4086


Habitual 02-02-2013 12:35 PM

at least I had all the right parts. :)

"While the shell or process is running, $0 holds the string value of the process name"
"While the shell or process is running, $$ holds the numerical value of the process ID"


Thanks.


All times are GMT -5. The time now is 02:32 PM.