Any occasion where .bashrc is favorable to .bash_profile?

Shell options (from shopt or set) are not inherited through the environment. Nor are aliases. If you want to, for example, enable failglob for all your shells, that needs to be in the RC file. An alias could be replaced with an exported function, but there's no workaround for the options.

It is also conventional & encouraged by the manual to have .bash_profile source .bashrc, so these configurations that you put in there will be loaded into both login and non-logic shells. If they're only in .bash_profile, they might never be loaded into a shell you actually use at all.

Another situation is where you have more complex configuration with actual executable code (for example, some advanced PROMPT_COMMAND) and want freshly-initialised variables for it to use in each shell. You probably wouldn't want those variables exported at all, or perhaps they are arrays and they can't be.

A final case would be for side-effecting command execution: displaying fortune or a to-do list in every new shell. That is not so much "configuration", but it is setting up your shell behaviour.


There is also the more general case where bash is not invoked as the login shell (because your session manager does something else, or it isn't your login shell, or ...) and your .bash_profile would never be processed at all. That may be out of scope for your concern, though.

Tags:

Shell

Bash

Bashrc