I was viewing my .bash_profile file, and I saw this written inside a block of if statement:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
Can someone explain what the second line is actually doing?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI was viewing my .bash_profile file, and I saw this written inside a block of if statement:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
Can someone explain what the second line is actually doing?
The second line “sources” the .bashrc
script; that means it loads and executes its contents in the same shell context. The result is the same as putting the contents of .bashrc
in .bash_profile
.
This statement is useful because the two files are used in different contexts: .bash_profile
is executed when bash
starts as a login shell, whereas .bashrc
is executed when bash
is started as a non-login interactive shell. Including .bashrc
in .bash_profile
allows it to be the single place for you to add customisation which you want to have in all interactive shells.
If .bashrc
wasn’t sourced using .
, its execution would spawn a new shell just for the duration, and its effects would be lost immediately.
/etc/init.d/
) to load the LSB functions (/lib/lsb/init-functions
) or to load external configuration files (such as those in /etc/default
).
Jan 31, 2015 at 19:58