1

On my work macbook, it seems my ~/.bash_profile doesn't get sourced every time a new terminal (tab or new window) is opened, and I have to do it manually. How can I automate this?

I read through Terminal: run source ~/.bash_profile every time start new terminal, but it didn't help because I don't currently use ~/.zshrc, or .bashrc

I am using Zsh shell

David
  • 131
  • There’s some missing details here like what shell are you using? Use the command echo $0 at the prompt to find out. What other init files do you have present like .bashrc or .zprofle? It helps immensely if you identify the version of macOS you’re on; please [edit] the question with that info. – Allan Apr 18 '23 at 18:09
  • Aside from considering using the appropriate bash script instead (i.e. whichever one gets run on a new terminal) I seem to recall iTerm2 has the option to configure a script to run. – JL Peyret Apr 18 '23 at 18:09
  • @Allan It seems I am usingzsh. The only other files beginning with . that I see under home is
    .DS_Store            .borgpass            .vscode/
    .Trash/              .cache/              .zsh_history
    .bash_profile        .config/             .zsh_sessions/
    .borgfiletest        .python_history      
    .borghealthcheck     .ssh/    ```
    
    – David Apr 18 '23 at 18:11
  • https://apple.stackexchange.com/a/297908/116013 – JL Peyret Apr 18 '23 at 18:12
  • 2
    Well, Zsh doesn’t source .bash_profile. You could create a .zprofile with a single line that sources your .bash_profile but I don’t recommend that. See: https://apple.stackexchange.com/q/388622/119271 – Allan Apr 18 '23 at 18:13
  • 1
    Why on earth do you want to process .bash_profile, a file written for bash shell language, from a different shell? – user1934428 Apr 24 '23 at 09:18

1 Answers1

2

Zsh ≠ Bash

As such, Zsh doesn’t source Bash’s .bash_profile. You need a .zprofile to be configured.

One quick (and dirty) way to get what’s in your .bash_profile into your Zsh .zprofile is to issue the command:

echo “. $HOME/.bash_profile” >> ~/.zprofile

This will cause .zprofile to source .bash_profile every time an interactive shell is opened. The commands appends what’s in the quotes to .zprofile - the command to source .bash_profile. It will create the file if it doesn’t exist.

It is much, much perferable however, to create a proper .zprofile because while mostly compatible with each other there are subtle difference that could break things (i.e. a colorized prompt).

As you’re starting with a new shell, this is an excellent opportunity to put things is the right place. See this Q&A ZSH: .zprofile, .zshrc, .zlogin - What goes where? for a more detailed look into what shell configuration files go where and what they do.

Allan
  • 101,432