I've been researching about how bash works, and so far I've learned the following things:

When starting a login shell, the first of the following files that exists gets executed:

~/.bash_profile, ~/.bash_login, ~/.profile

When starting a non-login shell (or a sub-shell) that is interactive, the ~/.bashrc file gets executed.

Also, .profile gets executed by other shells like sh. My question now is, what is the point of having a .bash_profile as well as a .bash_login? They both perform the same functions, and unlike .profile, both .bash_profile and .bash_login are both only read by bash. The only difference that I know between them is that .bash_login gets executed if .bash_profile is not present. So why is it there?

  • 1
    There is really no point in it. It's a compatibility thing, it has always been that way (eg. back in 1996). – mosvy Oct 8 '18 at 21:01
  • Compatibility with what though? – stackUnderflow Oct 9 '18 at 1:10
  • And how does having ~/.bash_login help with that – stackUnderflow Oct 9 '18 at 1:21
  • I guess some people had their startup file named that way, and in those times randomly breaking people's configs was not yet considered a feature -- but why not ask Chet Ramey himself? – mosvy Oct 9 '18 at 1:24
  • Duplicate of this? Also, .bash_login is explained in the manpage as "When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order" – ckujau Oct 9 '18 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.