How to load ~/.bash_profile when entering bash from within zsh?
An interactive bash
reads your ~/.bash_profile
if it's a login shell, or your ~/.bashrc
if it's not a login shell.
A typical .bash_profile
will contain something like:
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
so .bashrc
can contain commands to be executed by either login or non-login shells.
If you run bash -l
rather than just bash
, it should read your .bash_profile
.
Reference: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
Open ~/.zshrc
, and at the very bottom of the file, add the following:
if [ -f ~/.bash_profile ]; then
. ~/.bash_profile;
fi
Every time you open the terminal, it will load whatever is defined in ~/.bash_profile
(if the file exist). With that, you can keep your custom settings for zsh (colors, and etc). And you get to keep your custom shell settings in .bash_profile
file.
This is much cleaner than using bash -l
IMO.
If you prefer putting your settings in .bashrc
, or .bash_login
, or .profile
, you can do the same for them.
Similarly, you could also move the common profile settings to separate file, i.e. .my_common_profile
, and add the following to both .bash_profile
and .zshrc
:
if [ -f ~/.my_common_profile ]; then
. ~/.my_common_profile;
fi