How to load ~/.bash_profile when entering bash from within zsh?
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.
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
For those who have just installed zsh and want their alias from bash to work on zsh do the following
Open .zshrc file in vim like so
vi ~/.zshrc
Scroll to the bottom
- click "i" to enable write mode
- Tell zsh to load items from bash_profile when needed like so
source ~/.bash_profile
- Write and quit like so
:wq
- Refresh your zsh like so
That's it. Now all your saved alias in .bash_profile will be ready to use in zsh.source ~/.zshrc