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
ssh user@host, su - user, /bin/bash --login/etc/profile, which also sources/etc/bash.bashrc and then all files matching/etc/profile.d/*.sh~/.profile, which also sources~/.bashrcsu user, /bin/bash [-i], "subshells" as sometimes run by programs when they offer shells/etc/bash.bashrc~/.bashrcssh [-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. ^Z in nano| Shell type | /etc/profile | /etc/bash.bashrc | ~/.profile | ~/.bashrc |
|---|---|---|---|---|
| Login shells | X | X | X | X |
| Interactive non-login | X | X | ||
| Non-interactive | ||||
/bin/bash --posix | ||||
/bin/sh --login | X | X | X | X |
/bin/sh |
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.
if [ "$PS1" ]; then if [ "$BASH" ]; then if [ -f /etc/bash.bashrc] …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.disclaimer & imprint :: copyright :: backlinks :: page history :: index :: recent changes (all) :: go to top ::
Discussion