LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What does a single period ( . ) mean in bash? (https://www.linuxquestions.org/questions/programming-9/what-does-a-single-period-mean-in-bash-577903/)

BobTheSlob 08-17-2007 07:12 PM

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!

slakmagik 08-17-2007 07:19 PM

It's a synonym for 'source'.

BobTheSlob 08-17-2007 07:25 PM

I don't think I know what that means either.

pixellany 08-17-2007 07:28 PM

"." (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.

slakmagik 08-17-2007 07:34 PM

Quote:

Originally Posted by pixellany (Post 2862577)
"." (dot) has many meanings

He gave the example that indicated which meaning he meant.

Quote:

Originally Posted by BobTheSlob (Post 2862576)
I don't think I know what that means either.

'help source' (or even 'help .').

pixellany 08-17-2007 07:37 PM

Quote:

Originally Posted by digiot (Post 2862583)
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??....;)

slakmagik 08-17-2007 07:44 PM

No, actually, now that I think of it, I guess that should be bonus points, if anything. :)

BobTheSlob 08-17-2007 07:52 PM

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 :)

slakmagik 08-17-2007 07:58 PM

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.

BobTheSlob 08-17-2007 07:59 PM

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!

gnashley 08-18-2007 02:00 AM

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.


All times are GMT -5. The time now is 09:52 PM.