When I enter a eg. a new alias into my .bashrc
file I can't use it in that terminal window immediately and until recently I thought I had to restart the terminal to reload the .bashrc
file. Then I found out somewhere that if I write
. .bashrc
this will reload the .bashrc
file in the current window and I don't have to restart. This works fins but what is actually happening? Why does this reload the .bashrc
file?
Best Answer
Because
.
is a command.It's a shell built-in command, that reads the named file and executes the commands therein in the current shell process.
The Bourne Again shell also has
source
as a synonym for this command. But this is a Bashism (that the Bourne Again shell took from the C Shell). Albeit it is a Bashism that the Bourne Again shell shares with the TENEX C Shell, the Z Shell, and others (but not the Korn shell, note). The Single UNIX Specification only standardizes.
.Also note that the behaviour of
.
/source
subtly changes dependent from whether the Bourne Again shell is being run in its POSIX-compatible mode or not. (Again this is like other shells, although their non-standard behaviours are not the same as one another's. With the Z Shell, for example, there is a precompiled shell script mechanism, andsource
subtly differs from.
in its search path handling. The Korn shell's.
will run shell functions, for another example.)~/.bashrc
is merely one of several files whose contents are (dependent from how the shell process is invoked) automatically sourced at shell startup. There's nothing prohibiting it from being manually sourced. Although if its actions aren't idempotent, you might have some fixup work to do afterwards.Further reading