When invoked as bash (not sh) the start-up files that bash reads for a
login shell are, in order:
i) /etc/profile
and then the first of any of the following that exists:
ii) ~/.bash_profile OR
iii) ~/.bash_login OR
iv) ~/.profile
Non-login interactive bash shells (when changing or starting new shells
during a session) read only ~/.bashrc.
Non-login non-interactive bash shells (ie-when launched from inside a
script) check the startup file in $BASH_ENV, or $ENV if that doesn't
exist.
An easy way to make sure all three invocations of bash reference the same
start-up file is:
i) use .bashrc as your customized startup file
ii) create a .bash_profile containing only:
export BASH_ENV=~/.bashrc
if [ -f ~/.bashrc ]; then source ~/.bashrc; fi
This way, after reading /etc/profile a login shell will read the first
file found, ~/.bash_profile, which in turn reads ~/.bashrc
Non-login interactive shells will read ~/.bashrc as usual
Non-login non-interactive shells will read the ~/.bashrc assigned in
$BASH_ENV.
Reference 1: BASH's sourcing profiles order in execution
[sjing@prodpmcf151 ~]$ bash -cx 'env'
+ '[' -f /etc/bashrc ']'
+ source /etc/bashrc
++ '[' 17934 -gt 99 ']'
+++ id -gn
+++ id -un
++ '[' techdept = sjing ']'
++ umask 022
++ '[' '' ']'
++ shopt -q login_shell
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/colorls.sh ']'
++ '[' '' ']'
++ . /etc/profile.d/colorls.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/glib2.sh ']'
++ '[' '' ']'
++ . /etc/profile.d/glib2.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/gnome-ssh-askpass.sh ']'
++ '[' '' ']'
++ . /etc/profile.d/gnome-ssh-askpass.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/krb5-workstation.sh ']'
++ '[' '' ']'
++ . /etc/profile.d/krb5-workstation.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/lang.sh ']'
++ '[' '' ']'
++ . /etc/profile.d/lang.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/less.sh ']'
++ '[' '' ']'
++ . /etc/profile.d/less.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/vim.sh ']'
++ '[' '' ']'
++ . /etc/profile.d/vim.sh
++ for i in '/etc/profile.d/*.sh'
++ '[' -r /etc/profile.d/which-2.sh ']'
++ '[' '' ']'
++ . /etc/profile.d/which-2.sh
++ unset i
++ unset pathmunge
+ '[' '!' 1 ']'
+ env
Reference 2: UNIX/LINUX UNICODE FAQ
Reference 3: Useful 'find' Page
bash login profiles for all scenarios
Labels:
Scripting ( Shell Perl Python)