2

If bash is my shell, what should I put in ~/.bash_profile and what should I put in ~/.bashrc?

My understanding is that ~/.bash_profile is read on login, and ~/.bashrc is read for each new interactive non-login shell. I can set ~/.bash_profile to read ~/.bashrc if I want.

But since I can't actually think of anything that I don't want to always be set to some initial value, and since every Unix process (not only the shell) inherits the environment variables of its parent process, why wouldn't I just put everything into ~/.bash_profile and just forget about ~/.bashrc? What is the rationale for setting things again and again to the same value every time ~/.bashrc is read, when they could just be set once initially in ~/.bash_profile?

Or maybe what I'm really asking is what logically goes into each of ~/.bash_profile and ~/.bashrc, irrespective of my own requirements.

(I fully admit ignorance, and I'd also gladly be corrected on the above if my understanding is incorrect.)

osullic
  • 235
  • I've found a related question: Why have both .bash_profile and .bashrc? but it doesn't really explain the rationale of .bashrc to me. The answer over there says of .bashrc, "aliases, functions, etc [...] are per shell session items that are not inherited from environment." Well, aren't they inherited from the environment? – osullic Jul 13 '20 at 20:03
  • No, those things (aliases, functions, etc.) that are not inherited from the environment are indeed not inherited from the environment. – Gilles 'SO- stop being evil' Jul 13 '20 at 20:17
  • Once upon a time, room in the environment was at a premium. You wouldn't want it cluttered with interactive-shell specific things like PS1 that no other process would care about. – chepner Jul 14 '20 at 19:44

0 Answers0