LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-17-2007, 08:12 PM   #1
BobTheSlob
LQ Newbie
 
Registered: May 2005
Posts: 14

Rep: Reputation: 0
Question What does a single period ( . ) mean in bash?


I see this all the time in my startup scripts. For example

if [ -r /etc/rc.config ]; then
. /etc/rc.config

I know that says "if /etc/rc.config is a readable file then" but what does

. <somefile> mean?

I can't really find that in any documentation.

Thanks!
 
Old 08-17-2007, 08:19 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
It's a synonym for 'source'.
 
Old 08-17-2007, 08:25 PM   #3
BobTheSlob
LQ Newbie
 
Registered: May 2005
Posts: 14

Original Poster
Rep: Reputation: 0
Talking

I don't think I know what that means either.
 
Old 08-17-2007, 08:28 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
"." (dot) has many meanings:
  1. In a pathname it means "current directory"--eg. ./filename
  2. As a prefix to a filename, it causes it to be hidden--eg. .filename
  3. It is a synonym for the "source" command--used to pull an executable file into a script.--eg: . execfile (note the space)
  4. In a regular expression it matches any single character.
 
Old 08-17-2007, 08:34 PM   #5
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Quote:
Originally Posted by pixellany View Post
"." (dot) has many meanings
He gave the example that indicated which meaning he meant.

Quote:
Originally Posted by BobTheSlob View Post
I don't think I know what that means either.
'help source' (or even 'help .').
 
Old 08-17-2007, 08:37 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by digiot View Post
He gave the example that indicated which meaning he meant.
I figured that out after doing a bit of checking for answers. Any penalty for an "excess" answer??....
 
Old 08-17-2007, 08:44 PM   #7
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
No, actually, now that I think of it, I guess that should be bonus points, if anything.
 
Old 08-17-2007, 08:52 PM   #8
BobTheSlob
LQ Newbie
 
Registered: May 2005
Posts: 14

Original Poster
Rep: Reputation: 0
So apparently, according to man pages, it just returns the return value from the script used as its argument. Or, it returns the error from the script used as its argument.

So

. /etc/rc.config

is kind of like saying "if rc.config runs fine, then do this, otherwise spit out the error"

Yeah? This is OP if you aren't looking at names
 
Old 08-17-2007, 08:58 PM   #9
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Well, it also actually executes any commands in the sourced file in the current environment. In something like '. /etc/rc.config', it's saying to execute any commands in the file (including assignment to variables). The exit code is actually being ignored in that case.
 
Old 08-17-2007, 08:59 PM   #10
BobTheSlob
LQ Newbie
 
Registered: May 2005
Posts: 14

Original Poster
Rep: Reputation: 0
Hmm..I don't know what I just read but it's pretty different from what you just told me. What you said makes more sense though. I've seen the . used in many contexts where your description is obviously the right one.

Thanks!
 
Old 08-18-2007, 03:00 AM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,771

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
In the context you asked about, using the '.' or 'source' reads in the content of the named file and handles that content as if it were written into the script at the point where it is sourced from.
 
  


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
bash programming-append single line to end of file pheasand Linux - General 4 02-28-2014 10:41 AM
how do i produce a single digit random number in BASH? jaepi Linux - Newbie 8 04-30-2007 12:54 AM
Inittab - starting a single program as user XYZ via bash IK81 Linux - General 1 10-04-2006 09:00 AM
Convert an info file(bash.info.gz) to a single html file Darwish Linux - Software 2 09-24-2005 07:51 AM
In BASH shell, what is the difference in usage between single and double quotes? davidas Linux - Newbie 2 04-05-2004 04:00 AM


All times are GMT -5. The time now is 03:47 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration