Some time last week (week-ending April 16th), my raspberry pi stopped loading the .bashrc file whenever I connect to the unit. I have to manually run the .bashrc file using source for it to work. What gives?
Bash can be started in three ways: as a login shell (interactive or not), as an interactive shell (but not a login shell), and as neither. (All following quotations are from the "Invocation" section of the bash manpage.)
Bash is started as a login shell when you log in at the text VGA console, serial console or via ssh:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
.bashrc is not executed in this case. Most Linux distributions, including Raspbian, supply the user with a default
~/.profile that includes the following lines:
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
If you've added a
~/.bash_login file, your
~/.profile file will no longer be executed, and that might be why your
~/.bashrc is no longer being sourced on login. If not, check the contents of your
~/.profile to see if these lines have been changed or removed.
~/.bashrc is sourced automatically if you start an interactive (but non-login) shell, such as by typing
bash at the command prompt:
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.
~/.bashrc, some other file, or no file at all is sourced when a non-interactive shell is started, such as with
bash -c "somecommand" depends on the setting of the
When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute.