This .
does not refer to the current working directory as it usually does elsewhere. Rather, it is the short (and, it seems, the original) version of the source
command, which executes the file specified in the current shell (even if it is not executable), rather than in a child shell, which is what happens when you run with ./file
or bash file
. Functions defined, variables assigned, and modifications to the environment made in child shells are unknown to the parent shell, so if you want a file to do something to the current shell, you probably want to source
it.
$ type .
. is a shell builtin
$ help .
.: . filename [arguments]
Execute commands from a file in the current shell.
A common use of the source
or .
commands is to be able to immediately use aliases or functions defined in a particular file. For example, after making changes to a shell rc file, to use the new configuration immediately, one may run . .bashrc
(or . .zshrc
, etc).
It is also common for one file to source
another as you saw. For example, as a shell's rc file is executed automatically in every interactive shell of that type when it starts, you can incorporate configurations in other files in every interactive shell you run by having the rc file source
those files.
Both .
and source
work in the same way in the fish shell, but, of course, the syntax of the functions etc in the file you source
may be incompatible with shells other than the one they were written for.