(Bash) .bashrc vs. .bash\_profile

.bash_profile is executed when a log-in interactive shell is started.

.bashrc is executed when a non-log-in interactive shell is started (e.g. starting another bash shell from within bash).

.bashrc is NOT executed when a log-in interactive shell is started, so include the following snippet into .bash_profile so that it indirectly executes .bashrc:

# .bash_profile

# If .bash_profile exists, bash doesn't read .profile
if [[ -f ~/.profile ]]; then
    . ~/.profile
fi

# If the shell is interactive and .bashrc exists, get the aliases and functions
if [[ $- == *i* && -f ~/.bashrc ]]; then
  . ~/.bashrc
fi

References:

Written on May 4, 2022