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
/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:
su - user,
/etc/profile, which also sources
/etc/bash.bashrcand then all files matching
~/.profile, which also sources
/bin/bash [-i], "subshells" as sometimes run by programs when they offer shells
ssh [-t] user@host command,
/bin/bash -c command, shebang style script shells (
#!/bin/bash), and shells as run by programs when they offer shells, e.g.
|Shell type|| || || ||
Non-interactive shells either source
$BASH_ENV, or in POSIX mode
~/.profile is special because Bash actually looks for
~/.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_login do not exist; only
if [ "$PS1" ]; then if [ "$BASH" ]; then if [ -f /etc/bash.bashrc] …
ssh user@host commandor not. In case of these "non-interactive login shells" Bash executes
~/.bashrc. But in Debian Squeeze both files quit right at the start due to the fact that their first command is
[ -z "$PS1" ] && return.