How to load ~/.bash_profile when entering bash from within zsh? How to load ~/.bash_profile when entering bash from within zsh? shell shell

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

  1. Open .zshrc file in vim like so

     vi ~/.zshrc
  2. Scroll to the bottom

  3. click "i" to enable write mode
  4. Tell zsh to load items from bash_profile when needed like so
    source ~/.bash_profile
  5. Write and quit like so
    :wq
  6. Refresh your zsh like so
    source ~/.zshrc
    That's it. Now all your saved alias in .bash_profile will be ready to use in zsh.