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?

Thank you!

enter image description here

  • I'd like to point out that your hostname (badassmachinev2) might not be appropriate under SE's rules.
    – sir_ian
    Apr 18, 2017 at 2:11
  • I assume you're connecting over SSH, right? (Not locally or via serial or rsh or anything weird like that.)
    – Hydraxan14
    Apr 19, 2017 at 22:09
  • @Hydraxan14 yes, I connect through SSH.
    – Tam N.
    Apr 20, 2017 at 23:25

1 Answer 1


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.

Note that .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
        . "$HOME/.bashrc"

If you've added a ~/.bash_profile or ~/.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.

Additional Information

~/.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.

Whether ~/.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 $BASH_ENV variable:

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.

  • Thank you. I'm AFK now, but will look into ~/.profile when I get home.
    – Tam N.
    Apr 20, 2017 at 23:27
  • 1
    Thank you very much. Removing the ~/.bash_profile file fixed the problem :)
    – Tam N.
    Apr 25, 2017 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.