3

I recently bought and set up my Raspberry Pi 3.0 with Raspbian PIXEL. I use the default shell, bash.

Upon login, bash does not automatically execute my ~/.bashrc script. Every other Linux distro I've run does this automatically, so I'm at loss to why Raspbian doesn't.

How can I configure my pi to load the .bashrc when I log in? Is there another file that bash runs on startup? If so, what is it, and what's the syntax?

2 Answers 2

3

Upon login, bash does not automatically execute my ~/.bashrc script. Every other Linux distro I've run does this automatically, so I'm at loss to why Raspbian doesn't.

The first line of the default .bashrc should give you the answer:

# ~/.bashrc: executed by bash(1) for non-login shells.

It's for non-login shells, you are expecting it to be loaded for the login shell. And it's the same for any bash instance, regardless of the "Linux distro".


Is there another file that bash runs on startup?

Per man bash:

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.


what's the syntax?

Either of the files mentioned above is a bash script file. No special syntax is required.

1
  • 1
    I found that after I created the file ~/.bash_profile my ~/.bashrc was no longer read. This is because when I SSH in, ~/.profile, which sources ~/.bashrc, is never read because ~/.bash_profile exists instead. Hope that helps somebody.
    – Dave
    Commented Oct 7, 2019 at 5:20
0

This is something that has annoyed me for sometime when I ssh into a pi, and I'd have to run bash after successfully logging in to get a color prompt. And even then the bash configuration files I have setup in the pi user's $HOME directory are not loaded.

All that said, a cheap quick fix that I've applied on a local pi I ssh into.

Edit /etc/bashrc and append the below lines

# load user specific BASH configuration files
if [ -f $HOME/.bash_profile ]; then
  . $HOME/.bash_profile
fi

Then setup bash configuration settings within $HOME/.bash_profile to restore sanity 👩‍⚕️

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.