www.rodneybeede.com "I would love to change the world, but they won't give me the source code" - unknown

How bash reads startup files on various distros - Last Modified 2014-02-05 19:15 UTC - Created 2014-02-05 19:13 UTC

Some notes on how bash reads startup files. Some distros compile with the SYS_BASHRC flag which can add some startup files.

In most cases /etc/bashrc (or similar /etc) files are not read by bash itself by are sourced by other startup files instead. See /etc/profile, ~/.bash* files, ~/.profile, and /etc/skel/.bash* (or .profile) files.

login shell (interactive or non-interactive)
    First one that is readable
    Can use --noprofile option to disable all of these above options
    Upon exit reads ~/.bash_logout (and some distros /etc/bash.bash_logout)

non-login shell + interactive
    /etc/bash.bashrc    (Ubuntu/Debian SYS_BASHRC special)
    Can use --norc to disable
    Can use --rcfile to force one specific file instead
"sh" invocation

You also see on some distros /etc/bashrc (versus /etc/bash.bashrc). This is typically (see SYS_BASHRC for exception) not read by bash itself but instead sourced by ~/.bashrc (which is typically sourced by ~/.profile or ~/.bash_profile).

Other invocation methods have environment variables that specify a startup file to read. POSIX mode (--posix) turns off startup files except for env.

Consult the bash man page or Bash Reference Manual for more info.

To tell if your distro uses the SYS_BASHRC compile option try "man bash" on your running distro and look in the INVOCATION section.