0 notes &
Bash’s init files
I finally understood the shell init files for Bash. I think my block might have been due to a left-over confusion from tcsh.
When bash is interactive it runs profile or bashrc, not both.
- If its interactive and login, it runs profile.
- If its interactive and not login, it runs bashrc.
If its not interactive, it runs neither (unless you tell it to).
Easy, right?
My problem was that I was always thinking that a login shell might not be interactive, and so profile might run when not interactive.
There is an environment variable to set to get some init done in non-interactive shells, but normally nothing is done for non-interactive shells. ($ENV or $BASH_ENV.)
The only remaining problem is the “unless you tell it to” from above. This problem, however, is much easier to work with conceptually. In the simple sense, only profile can be easily told to load for non-interactive shells by passing —login. So, bashrc is exclusively interactive and profile is presumptively interactive. Sadly, because of this minor difference, it’s not as simple as it sounds to separate.
I’m still not quite sure how to deal with this. The easy solution is just to source one from the other. That is, source bashrc from within profile. This is the solution that is adopted by almost every GNU/Linux distribution that I’ve ever seen. I believe this to be slightly suboptimal. It defeats the entire purpose of the separation.
Really, though, my problem is that I don’t know what should be in one file and what should be in the other. What, exactly, should I make sure is loaded in login shells that is not as important in non-login shells?