I found that those are .bash_profile, .bashrc, .bash_login, .profile.
What's the reading sequence between them?
I found that those are .bash_profile, .bashrc, .bash_login, .profile.
What's the reading sequence between them?
Basically, if it's a login shell it sources /etc/profile then .bash_profile. If it's not a login shell, but you're at a terminal, it sources /etc/bash.bashrc then .bashrc.
But it's actually a lot more complicated.
The way I read the man page:
if bash_mode; then
if login_shell; then
if test -e /etc/profile; then source /etc/profile; fi
if test -e .bash_profile; then source .bash_profile
elif test -e .bash_login; then source .bash_login
elif test -e .profile; then source .profile; fi
elif interactive_shell || remote_shell; then
if test -e /etc/bash.bashrc; then source /etc/bash.bashrc
if test -e .bashrc; then source .bashrc; fi
elif test -n "$BASH_ENV"; then
source "$BASH_ENV"
fi
elif sh_mode; then
if login_shell; then
if test -e /etc/profile; then source /etc/profile; fi
if test -e .profile; then source .profile; fi
elif interactive_shell; then
if test -n "$ENV"; then
source "$ENV"
fi
fi
fi
It's a login shell any time the shell is run as -bash (note the minus sign) or with the -l option. This usually happens when you log in using the login command (Linux virtual consoles do this), over ssh, or if your terminal emulator has the "login shell" option enabled.
It's an interactive shell any time standard input is a terminal, or bash was started with the -i option. Note that if the shell is also a login shell, bash doesn't check if the shell is interactive. For this reason, .bash_profile usually contains code to source .bashrc, so you can share the same settings between interactive and login shells.
INVOCATIONsection of the bash manual. Meanwhile I am sure this is a duplicate of something. – jw013 Jul 25 '12 at 16:44An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option.- from man bash. This means if any of these requirements are not fulfilled it is a non-interactive shell, e.g. if you run a script with the#!/bin/bashshebang it is a non interactive shell. – Ulrich Dangel Jul 25 '12 at 17:00--login) means it takes a separate codepath from an interactive shell. – Mikel Jul 25 '12 at 18:29