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?


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, and source 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

  • "Special Built-In Utilities: dot". Shell Command Language. Single UNIX Specification. Issue 6. IEEE 1003.1. 2013. The Open Group.
  • bashisms. Greg's wiki.
  • "Bourne shell builtins". Bash Reference Manual. Free Software Foundation.
  • "Bash builtins". Bash Reference Manual. Free Software Foundation.
  • "Bash Startup Files". Bash Reference Manual. Free Software Foundation.
  • What is the difference between executing a Bash script vs sourcing it?

help . would tell you:

.: . filename [arguments]

Execute commands from a file in the current shell.

Read and execute commands from FILENAME in the current shell.  The
entries in $PATH are used to find the directory containing FILENAME.
If any ARGUMENTS are supplied, they become the positional parameters
when FILENAME is executed.

Exit Status:
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read.

Saying . .bashrc executes (sources) the file .bashrc which makes the changes made to the file available in the current session.

By default, ~/.bashrc would be read at login.

. is a synonym for source.