Table of Contents

Bash shell startup files in Debian Squeeze

Whenever I need to research which files are actually read or executed to set up the Bash environment at startup my brain refuses to cooperate. One thing is to understand the Bash manual about Startup Files and the Bash man page. That's still somewhat OK, but when I start looking at the actual file contents1) my gray matter's neurons begin to act in weird ways2).

So, I ran my own tests on a fresh new installation of Debian Squeeze. To keep things simple, at first I only looked at shells invoked by ssh logins, su, /bin/bash and such. However, POSIX mode and /bin/sh are mentioned in the overview table. Anyway, here is what the tests boil down to.

Mainly, 4 files are read: /etc/bash.bashrc, /etc/profile, ~/.bashrc, ~/.profile

Login shells

Interactive non-login shells

Non-interactive shells

Overview table

Shell type /etc/profile /etc/bash.bashrc ~/.profile ~/.bashrc
Login shells X X X X
Interactive non-login X X
/bin/bash --posix
/bin/sh --login X X X X

Non-interactive shells either source $BASH_ENV, or in POSIX mode $ENV.


~/.profile is special because Bash actually looks for ~/.bash_profile, ~/.bash_login and ~/.profile, in this order, and Bash runs only the 1st of these 3 it finds (if it is readable). However, on a fresh Debian Squeeze ~/.bash_profile and ~/.bash_login do not exist; only ~/.bashrc, ~/.profile, and ~/.bash_logout.

Such as if [ "$PS1" ]; then if [ "$BASH" ]; then if [ -f /etc/bash.bashrc] …
I am just trying to express politely what I think :-X
Actually, Bash tries to detect whether it is run by ssh user@host command or not. In case of these "non-interactive login shells" Bash executes /etc/bash.bashrc and ~/.bashrc. But in Debian Squeeze both files quit right at the start due to the fact that their first command is [ -z "$PS1" ] && return.