Neither .bashrc nor .profile gets read when bash is set as the shell in macOS 11
I know macOS 11 is trying hard to convince me to use zsh
, but it also says I can choose another shell, which I have: chsh -s /bin/bash
. The problem is, it no longer works as it did, as it neither reads my .profile
nor my .bashrc
when I start Terminal.app
or iTerm.app
. I just get this:
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$
If I now manually type bash
, things happen as they should:
bash-3.2$ bash
[Timer is unset. Use timer_start] core utils setup finished
[3] Executing $HOME/.bashrc
[7] Reading utility functions and aliases
[10] core utils setup finished
[14] Reading aliases and functions
[22] ssh aliases
[26] conversions
[30] Use htop if available
[36] small utils and aliases
[40] aliases: setting up node aliases
[44] aliases: finished setting up node aliases
[48] webserver aliases
[52] global aliases and functions finished
[56] Reading utils for git prompt
[63] Reading bash completion files
[69] /Users/carlerik/.bash_completion.d/azure
[75] /Users/carlerik/.bash_completion.d/git
[89] /Users/carlerik/.bash_completion.d/npm
[95] /Users/carlerik/.bash_completion.d/tmux
[100] Reading color codes
[105] Read /Users/carlerik/.bash.d/colors
[130] Read /Users/carlerik/bin/z.sh
[135] Reading local settings for this machine
[140] Load personalized bashrc for mac
[152] Read /Users/carlerik/.bashrc.local
This setup is missing 'direnv'. Please install it for per-directory overrides
[157] Finished bash setup
[205] Read /Users/carlerik/.secret
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
carlerik at idas-imac in ~
$
All the timing stuff is due to a DEBUG
setting I have enabled (my .bashrc
in my dotfiles). So it works as normal.
How can I get macOS 11 to use my .bashrc and/or .profile on startup?
I have even tried overriding the terminal settings in both apps from the standard logon shell to /bin/bash --rcfile $HOME/.bashrc
with no further success (just as a temporary workaround to see if it was possible to force it to read my init files).
For reference, this is my .profile:
printf "Reading .profile"
export DEBUG=1
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# other stuff
# ...
# other stuff end
if [ -f "$HOME/.profile.local" ]; then
. "$HOME/.profile.local"
fi
The answer to this was hinted to by @mmmmmm: without my knowledge, a .bash_profile
file had been added, thus making bash choose to read that instead of .profile
.
The culprit was the installer script for gcloud
, the CLI for the Google Cloud SDK.
For my cross-platform dotfiles, I have moved these mac-specific settings to another file which is only read when using mac (in my setup).