LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-09-2008, 07:32 AM   #1
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Question is $$ a variable of some sort? it seems to contain a value..


Code:
sasha@darkstarSSI:~$ echo $PWD
/home/Sasha
*sasha@darkstarSSI:~$ echo $$PWD
8027PWD
*sasha@darkstarSSI:~$ echo $$
8027
*sasha@darkstarSSI:~$ echo $$$
8027$
*sasha@darkstarSSI:~$ echo $
$
sasha@darkstarSSI:~$ su
Password: *****************
root@darkstarSSI:/home/Sasha# echo $$
13569
root@darkstarSSI:/home/Sasha# exit
exit
sasha@darkstarSSI:~$ echo $$PWD
8027PWD
sasha@darkstarSSI:~$
just a curiosity..
Is a double-dollarsign actually a variable? If so/not then what is the value being returned by it as seen above? A different value for Sasha than for root, too.

How I noticed this:
I was reading the kernel Makefile, and came across this little section:

Code:
help:
	@echo  '  Building external modules.'
	@echo  '  Syntax: make -C path/to/kernel/src M=$$PWD target'
	@echo  ''
	@echo  '  modules         - default target, build the module(s)'
	@echo  '  modules_install - install the module'
	@echo  '  clean           - remove generated files in module directory only'
	@echo  ''
.. and there, the second @echo line has M=$$PWD target which I thought might be a typo, so I tried the echo command as seen in the first [code] tags above.

I tried running `make help` to see what got printed, but the above help: section did not get printed to the console.

Sasha

UPDATE: The value returned by $$ is the PID of the bash console in use! However, it still seems like a typo in the Makefile (unless make interprets it differently) because "${bashPID}${PWD}" doesn't seem really useful, to me anyhow.

Last edited by GrapefruiTgirl; 06-09-2008 at 07:38 AM. Reason: Discovered something..
 
Old 06-09-2008, 07:45 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
ABS---Table B1

$$ = the process ID of a script

I did a few experiments entering "$$" as different users, but I still don't totally understand what is happening.
 
Old 06-09-2008, 07:47 AM   #3
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
$$ is the PID of the script's current running process. I'm willing to bet if you issue another $$ and then "ps -ef | grep -i bash", you will find a Bash process with the number returned by $$.

$$ wouldn't return the same number if you wrote a script with "echo $$" in it, as a new process is spawned to execute a script. Then again, this is all theoretical, as I don't have a Linux (or UNIX) machine within reach, right now.

Ref #1. TLDP:Advanced Bash HOWTO Guide:Internal Variables

Last edited by indienick; 06-09-2008 at 07:50 AM.
 
Old 06-09-2008, 07:56 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Yes, for the test with "echo $$" the meaning of the double dollar is that explained in the previous posts, but in a Makefile you have to put a double $$ to retrieve the value of a shell variable. The $$PWD is replaced by the value of the PWD variable. The single dollar sign in Makefiles is meant to call a macro.
 
Old 06-09-2008, 08:11 AM   #5
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Solved.

Quote:
Originally Posted by indienick View Post
$$ is the PID of the script's current running process. I'm willing to bet if you issue another $$ and then "ps -ef | grep -i bash", you will find a Bash process with the number returned by $$.

$$ wouldn't return the same number if you wrote a script with "echo $$" in it, as a new process is spawned to execute a script. Then again, this is all theoretical, as I don't have a Linux (or UNIX) machine within reach, right now.

Ref #1. TLDP:Advanced Bash HOWTO Guide:Internal Variables
Quote:
Originally Posted by colucix
Yes, for the test with "echo $$" the meaning of the double dollar is that explained in the previous posts, but in a Makefile you have to put a double $$ to retrieve the value of a shell variable. The $$PWD is replaced by the value of the PWD variable. The single dollar sign in Makefiles is meant to call a macro.
__________________
Theory is when you know all and nothing works. Practice is when all works and nobody knows why. In this case we have put together theory and practice: nothing works... and nobody knows why! (Albert Einstein)
Thanks to you both for the excellent answers; I did try googling the $$ but nothing specific turned up on the first pages or so. I didn't go too mad over it as it was more a curiousity than anything, but I have learned something once again today, from each of you.

PS - Colucix, I do like that Einstein quote in your signature

PPS -
Quote:
Originally Posted by indienick View Post
...as I don't have a Linux (or UNIX) machine within reach, right now.
-- I'm sorry to hear that, you must feel uncomfortable I would! Heh heh, well I hope you are not in a room with a lot of windows.

Cheers!
sasha

Last edited by GrapefruiTgirl; 06-09-2008 at 08:21 AM.
 
Old 06-09-2008, 09:23 AM   #6
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Quote:
Originally Posted by GrapefruiTgirl
-- I'm sorry to hear that, you must feel uncomfortable I would! Heh heh, well I hope you are not in a room with a lot of windows.
Spasiba Sashinka, sadly though, I am in a Windows-only office.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: removing a variable substring from a string variable in sh script gnparsons Programming 2 06-04-2008 05:21 PM
selection sort compiles but does not sort the array as desired ganesha Programming 2 04-20-2008 07:44 AM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 11:23 AM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 08:40 PM
Scripting: accessing a variable stored in a variable? tomolesonjr Linux - Newbie 5 05-05-2006 08:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:21 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
Open Source Consulting | Domain Registration