Hacker News new | past | comments | ask | show | jobs | submit login

as far as I can tell when I open new shells .profile isn't read

True, iff you have a .bash_profile. Bash only reads the first of ~/.bash_profile, ~/.bash_login, ~/.profile. It will ignore the rest of the list once it's found an existing file.




Still, they're not read with every new interactive shell. They're read only with login shells. From the manual:

> 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,

> When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc

So, this is wrong:

> bashrc refers to something that runs in each and every new shell

Because .bashrc doesn't run when you execute a shell script, and doesn't run when you use `bash -c`.

And this is wrong:

> profile refers to something that runs only in interactive shells

Because it does run in non-interactive shells when they're login shells, and because it implies that it runs in every interactive shell, which it doesn't. It only runs in login shells.


Insanely enough, this is set up wrong in Debian and derivatives, where bash_profile sources bashrc as a default from /etc/skel, leading to damning "not a tty" messages because at some point it calls some tty requiring command unconditionally.


This explains so many of my problems. Thank you.


https://hackernoon.com/bash-profile-vs-bashrc-vs-bin-bash-vs...

Note that in macOS every new Terminal (tab) opens a login shell, while most GUI Linux environments don't. (In Tmux/screen it depends on the configuration).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: