-   Linux - Newbie (
-   -   Writing a function, question about a symbol's meaning (

Alex_Dc 10-14-2009 09:15 PM

Writing a function, question about a symbol's meaning
Generally I prefer to avoid asking simple questions, but I can't seem to get any information on this one. If I were to write this function, for example:

if [ -f ~/.bashrc ]; then
. ~/.bashrc

what does the '.' in the second line indicate ('.' ~/.bashrc)?

smeezekitty 10-14-2009 09:17 PM

sure its not a mistake? i dont see any reason for it to be there

i92guboj 10-14-2009 10:07 PM

'.' is equivalent to 'source'. Both are bash builtins, so, check the bash man page to see what 'source' does.

The basic purpose of 'source' is to dump the contents of a shell script on the current shell, instead of spawning a new sub-shell. This is done this way because in bashrc you usually set a number of variables, and setting them into a subshell really makes no sense, since they will go away when the script exits. So, if you want a shell to run on the current shell you 'source' it instead of running it the traditional way.

Alex_Dc 10-14-2009 10:25 PM


OK, I get the general idea. Now I just have to read the man for source and learn what sub-shells are. :D That's easy enough though, I can take it from here. Thank you!

All times are GMT -5. The time now is 09:43 AM.