.bashrc not sourced in iTerm + Mac OS X

In iTerm2, none of these solutions worked for me. I was able to get it to properly read my .bashrc file by adding the command

source ~/.bashrc 

to the Send text at start: field in Settings/General for my iTerm profile.

enter image description here


Bash will source EITHER .bash_profile or .bashrc, depending upon how it is called. If it is a login shell, Bash looks for ~/.bash_profile, ~/.bash_login, or ~/.profile, in that order, and sources the first one it finds (and only that one). If it is not a login shell but is interactive (like most terminal sessions), Bash will source ~/.bashrc.

Likely, iTerm is looking for ~/.bashrc. If it's configured to start as a login shell, it will look for ~/.bash_profile. It's almost certainly an error within the config file rather than that the shell is not sourcing it.

I would put a line at the beginning of each file. At the top of ~/.bash_profile:

export BASH_CONF="bash_profile"

And at the top of ~/.bashrc:

export BASH_CONF="bashrc"

Then, open a new iTerm and type

$ echo $BASH_CONF

That should confirm the file is being sourced and you can look into the syntax of the file.


I just wonder do you really use Bash? May be you can use echo $SHELL, it is quite possible that you are using zsh, have you installed on-my-zh?

Acutually I encounter the same problem as you, I fix it by configuring ~/.zshrc instead either ~/.bash_profile for login shell or ~/.bashrc for non-login shell.

Maybe you can have a try

Tags:

Bash

Mac