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! |
It's a synonym for 'source'.
|
I don't think I know what that means either.
|
"." (dot) has many meanings:
|
Quote:
Quote:
|
Quote:
|
No, actually, now that I think of it, I guess that should be bonus points, if anything. :)
|
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 :) |
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.
|
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! |
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. |