Closed FranklinYu closed 2 years ago
@peterb Sorry for taking more than a year to do it! It went out of my radar.
Looks very nice! I think this will help people using Bash on OS X. Does [[ $- == *i* ]]
check if what's running is an interactive shell? Maybe worth mentioning that. By the way I started using ZSH on OS X after the conversations we had.
The description of this MR looks good for a Blog post.
Very thorough explanation!
This is a follow-up on #437 and #438.
background knowledge for Bash
If you run a Bash within a Bash, you are in a subshell. For example, if you execute
bash
after logging in, the shell process structure is like this:Then Bash No.0 would be the “interactive, login” shell, loading
~/.bash_profile
(falling back to~/.profile
for compatibility) but not~/.bashrc
. In contrast, Bash No.1 would be an “interactive, non-login” shell, loading~/.bashrc
but none of the profiles. Things are simpler in Linux workstation because Desktop Environments (GNOME, KDE Plasma, etc.) are typically the login shell, so all the Bash in terminal emulators (like GNOME Terminal) are non-login shells reading~/.bashrc
as expected. macOS is the weird guy: every new tab in the terminal (both Terminal.app and iTerm2) is a login shell (looks like a new session). This macOS issue isn’t Bash-specific, but Zsh loads~/.zshrc
regardless of the “login shell” bit, so Zsh users don’t even feel it.The official solution, is to source
~/.bashrc
in~/.bash_profile
, for a few reasons:chruby
) only need to specify once. Less typo, no need to synchronize rc-file and profile.~/.profile
,~/.bash_profile
is Bash-specific (hence the name), so we don’t need to test whether in Bash. As a result, this won’t affect other POSIX shells (or shells that may or may not read~/.profile
).~/.profile
, shared by various POSIX shells, if desired.other notes
test
), because~/.bash_profile
should only be read by Bash, not any random POSIX shell.source
instead of.
for the same reason.chruby
users. This note might sound too verbose; please adjust it to your taste.