In ~/.bash_profileI have :
if [ -f ~/.bashrc ]; then source ~/.bashrc
fiIn ~/.bashrc I have some aliases
When I load a new iTerm window, my aliases do not work. If I source ~/.bashrc they work. If I source ~.bash_profile they work.
Isn't at least one of these supposed to be sourced automatically?
What might be causing it not to work properly?
3 Answers
The answer is simple, almost evident in the question. Here's why:
The shell zsh is not bash, it is a different shell. zsh will not use the default files built for bash: .bashrc or .bash_profile. These two files are startup configuration files for bash. zsh has its own startup configuration files.
You can find out more about them here on the zsh intro page:
There are five startup files that zsh will read commands from:
$ZDOTDIR/.zshenv $ZDOTDIR/.zprofile $ZDOTDIR/.zshrc $ZDOTDIR/.zlogin $ZDOTDIR/.zlogout
You had mentioned your aliases don't work, to fix this, apply your aliases here like so:
~/.zshrc
alias sz='source ~/.zshrc' # Easily source your ~/.zshrc file.
alias ls='pwd; ls --color' # Alias 'ls' to: pwd + ls + color. 5 If you are using zsh then to force source .bash_profile
in ~/.zshrc add the line below
source ~/.bash_profileP.S - I havent investigated whether this can cause any problem.
5Copy the lines from ~/.bash_profile to ~/.zshrc
cat ~/.bash_profile >> ~/.zshrcAnd open a new terminal tab/window or use source ~/.zshrc