24435 bash 3 0 /etc/profile
24435 bash 3 0 /etc/profile.d/
24435 bash 3 0 /etc/profile.d/256term.sh
24435 bash 3 0 /etc/profile.d/colorgrep.sh
24435 bash 3 0 /etc/profile.d/colorls.sh
24435 bash 3 0 /etc/profile.d/lang.sh
24435 bash 3 0 /etc/profile.d/less.sh
24435 bash 3 0 /etc/profile.d/which2.sh
24435 bash 3 0 /etc/profile.d/sh.local
24435 bash 3 0 /home/centos/.bash_profile
24435 bash 3 0 /home/centos/.bashrc
24435 bash 3 0 /etc/bashrc
24736 bash 3 0 /home/centos/.bashrc
24736 bash 3 0 /etc/bashrc
24736 bash 3 0 /etc/profile.d/
24736 bash 3 0 /etc/profile.d/256term.sh
24736 bash 3 0 /etc/profile.d/colorgrep.sh
24736 bash 3 0 /etc/profile.d/colorls.sh
24736 bash 3 0 /etc/profile.d/lang.sh
24736 bash 3 0 /etc/profile.d/less.sh
24736 bash 3 0 /etc/profile.d/which2.sh
[1] http://www.brendangregg.com/blog/2014-07-25/opensnoop-for-li...So your capture here doesn't show only the files that bash itself decided to load. You also won't see the fallback files (e.g. bash will open .profile if .bash_profile doesn't exist).
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.
> 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.
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).
https://blog.flowblok.id.au/2013-02/shell-startup-scripts.ht...
On a Mac you usually end up adding
if [ -f ~/.bashrc ]; then
. ~/.bashrc;
fi
To your .profile or .bash_profile.Just read that part and now I can’t help but question the rest of it before even reading it
Apple breaks it, but there is.
Here’s info, https://unix.stackexchange.com/questions/170493/login-non-lo...
ZSH follows the same for login/non-login but I don’t see it for interactive.
if [ -n "$PS1" ] ; then
[ -r ~/.bashrc ] && . ~/.bashrc
[ -r ~/.bash_login ] && . ~/.bash_login
fiNever.
TFA has got it wrong.
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option.
So interactive, non-login shells only.
But also:
When invoked as an interactive shell with the name sh , bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. [A] shell invoked as sh does not attempt to read and execute commands from any other startup files
So only when invoked as bash, not as sh.
I'm not an expert on bash exactly though I am a heavy shell user (POSIX shell for scripting) but this part doesn't sound right. When is .bashrc ever executed when bash isn't interactive? And as far as I can tell when I open new shells .profile isn't read. I am using Linux and tmux and the reason I mention tmux is that it opens bash as a login shell and therefore .bash_profile is also loaded. Is this a mac OS thing or the version of bash mac OS comes with, which I believe is really old due to some license issues.