Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using iTerm in Mac OS X 10.6. It seems when i open iTerm, neither .bashrc nor .bash_profile is sourced. I can tell because the aliases defined in .bashrc don't work. How to fix?

share|improve this question
add comment

migrated from stackoverflow.com Aug 7 '11 at 9:57

This question came from our site for professional and enthusiast programmers.

7 Answers

up vote 9 down vote accepted

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.

share|improve this answer
add comment

On my 10.6 machine ~/.profile is sourced. So a source .bashrc entry in ~/.profile should do the job.

share|improve this answer
add comment

Put your alias definitions in the bash profile file, you have to create the file but it will be sourced automatically. I create a separate file called alias.configuration and source it in .bash_profile just because I have another user defined and want to have the same alias set.

share|improve this answer
    
Actually neither .bashrc nor .bash_profile are sourced. –  Computist Aug 7 '11 at 6:02
add comment

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

share|improve this answer
    
What happened when you did what the accepted answer suggests? No output? –  Daniel Beck Jun 13 '12 at 18:15
    
Right. I got no output, and iTerm 2 just loaded the default bash shell with none of my aliases. –  Mark Struzinski Jun 13 '12 at 18:25
    
That answer was broken until just now -- the second snippet was supposed to go into ~/.bashrc. Edited it. –  Daniel Beck Jun 16 '12 at 6:13
add comment

In iTerm2, ensure you're using "login shell" instead of a custom command including "login", which doesn't do what you expect.

share|improve this answer
add comment

Add

set -x

to the beginning of /etc/profile. This gives you a line-by-line account of everything that gets executed when bash starts up, including files sourced from within /etc/profile, ~/.bash_profile, etc. It's a bit daunting if you don't understand bash scripting very well, but you may be able to see if there is an error in a start-up file, and the output will be useful for someone proficient in bash to help you locate your problem.

You can remove the set -x line when you're finished troubleshooting.

share|improve this answer
add comment

On my 10.9 machine ~/.bash_profile is sourced. So a source .bashrc entry in ~/.bash_profile should do the job.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.