LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-01-2013, 08:49 PM   #1
BobShumaker
LQ Newbie
 
Registered: Feb 2013
Posts: 3

Rep: Reputation: Disabled
Cool $$$ 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?
 
Old 02-01-2013, 09:10 PM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
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.
 
1 members found this post helpful.
Old 02-01-2013, 09:38 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
$$ 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.

Last edited by shivaa; 02-01-2013 at 09:39 PM.
 
Old 02-02-2013, 11:55 AM   #4
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Quote:
Originally Posted by shivaa View Post
$$ 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?
 
Old 02-02-2013, 12:06 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by Habitual View Post
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
 
Old 02-02-2013, 01:35 PM   #6
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cursor does not move to the bottom line and overwrite to same line on command line mesuutt Linux - Newbie 3 02-25-2012 09:04 AM
Print all PID folders from /proc line-by-line with this format (( PID: command-line )) courteous Linux - Newbie 7 12-12-2010 05:47 PM
awk command line: blank line record sep, new line field sep robertmarkbram Programming 4 02-21-2010 06:25 AM
xine command line? or some other command line only engine? lumix Linux - Software 2 08-10-2007 11:46 AM


All times are GMT -5. The time now is 02:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration