Tell me more ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I put some alias commands in my .bashrc file, so that they might be loaded everytime I open a new Terminal window. Yet this doesn't happen.

I have to select run script: in the Terminal>Preferences>"MyDefaultTheme">Shell prefpane and add: source .bashrc && clear for it to work...

This seems odd since many tutorials only say you just have to add to the .bashrc file and all is good.

Note that I don't run in bash when using the terminal, I like the other (default) one (don't know what it is) better, because it show me where I am all the time eg:

>>d54c6b47b:~ romeo$

in stead of:

>>bash$

In bash all is loaded as should be.

So my question is, why didn't my .bashrc file load automatically and did I have to add the option to call it everytime?

Also some tutorial told me to do something like:

$alias la=’ls -la’ >> ~/.bashrc

which should write the alias to my .bashrc, this doesn't work either...

Note that I'm a UNIX novice, so be gentle.

share|improve this question
I think this is very close to apple.stackexchange.com/questions/7984/…. – boehj Apr 27 '11 at 21:13
@boehj well it mentions "not loading .bashrc" but that's about it. – koiyu Apr 27 '11 at 23:58
OK, sorry if I confused things here. – boehj Apr 28 '11 at 1:20
You probably like csh (or another variant) better. But you should know that the >>bash$ can be changed :) – vol7ron Jun 6 '12 at 1:13

7 Answers

up vote 16 down vote accepted

Just put that in your .profile file from your home dir and it should work the next time you start a new shell or after you run "source ~/.profile"

This link clearly states the order in which the startup files are read and loaded by the shell: http://hayne.net/MacDev/Notes/unixFAQ.html#shellStartup

share|improve this answer
accepted this one because it is has a solution (and it was the first of two near identical posts). – romeovs Apr 28 '11 at 5:15
this worked for me, thanks – marcgg Jun 6 '11 at 9:12

Been there, done that. What I came aware of, OS X doesn't read .bashrc file on bash start. Instead, it reads the following files (in the following order):

  1. /etc/profile
  2. ~/.bash_profile
  3. ~/.bash_login
  4. ~/.profile

See also Chris Johnsen's informative and useful comment:

By default, Terminal starts the shell via /usr/bin/login, which makes the shell a login shell. On every platform (not just Mac OS X) bash does not use .bashrc for login shells (only /etc/profile and the first of .bash_profile, .bash_login, .profile that exists and is readable). This is why "put source ~/.bashrc in your .bash_profile" is standard advice

I usually just put the things that I'd normally put in ~/.bashrc to ~/.profile — has worked so far like a charm.

share|improve this answer
8  
By default, Terminal starts the shell via /usr/bin/login, which makes the shell a login shell. On every platform (not just Mac OS X) bash does not use .bashrc for login shells (only /etc/profile and the first of .bash_profile, .bash_login, .profile that exists and is readable). This is why “put source ~/.bashrc in your .bash_profile” is standard advice. – Chris Johnsen Apr 28 '11 at 4:21
2  
Re "I usually just put the things that I'd normally put in ~/.bashrc to ~/.profile": For maximum compatibility I recommend you follow Chris Johnsen's advice and place anything that you want to apply to non-login shells in ~/.bashrc and add "source ~/.bashrc" to your ~/.bash_profile to run it for login shells. Otherwise, it won't work for sub-shells, or if Terminal changes to create non-login shells, or if you ever use xterm or another terminal program that create non-login shells by default, or if you might want to use the same setup on another OS. – Chris Page Aug 14 '11 at 1:35
1  
On a related note, on Mac OS X you should consider having ~/.bashrc run /etc/bashrc to pick up global behaviors. In particular, there's code in /etc/bashrc to update the working directory at each prompt, which is what enables Terminal to display the proxy icon, create new terminals at the same directory, and restore the working directory for Resume and Window Groups. – Chris Page Aug 14 '11 at 1:38
For me, sourcing .bashrc from .bash_profile didn't work. But sourcing .bashrc / .bash_profile from .profile worked. – Rajkumar Masaniayan Jan 9 at 8:02
Upvote for "This is why "put source ~/.bashrc in your .bash_profile" is standard advice" – JD. Mar 1 at 16:07
show 1 more comment

I put everything into ~/.bashrc and just source ~/.bashrc in .profile.

This allows screen and xterm (and i guess tmux) sessions to inherit my environment as non-login sessions only run .bashrc, whereas login sessions (eg terminal or iTerm) only run .profile.

share|improve this answer

Sourcing .profile in .bash_profile did it for me

echo 'source ~/.profile' >> ~/.bash_profile
share|improve this answer

I found that after installing rvm (auto-installer, no manual edits) it had created a ~/.bash_login file for itself, where I previously never had one.

However, this mean that my ~/.profile setups and aliases no longer got loaded! Lots of shortcuts disappeared. I thought they ran sequentially, not exclusively :-/

I added

. ~/.profile 

to ~/.bash_login to chain things as I expected.

share|improve this answer
+1, this is situation I had. I found that either .bash_login or .bash_profile will prevent .profile from being executed... No idea why bash feels the need to have so many conflicting startup files. – RichVel Mar 13 at 21:21

Putting...

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

...in ~/.bashrc, and then source ~/.bashrc into my ~/.bash_profile didn't work for the Terminal program that comes installed.

But then I went to the menu drop-down Edit > Profile Preferences, Title and Command tab, and selected Run command as a login shell from the command section of that page.

After doing so, starting a new terminal shows the desired result when I type

 type rvm|head -1

i.e. "rvm is a function". It did not do that until I made this change, and it's the only change I made after the .bash_profile and .bashrc changes described in other answers here.

share|improve this answer

First of all let me tell you that ~/.bashrc is the file which is executed every time a second shell is called up (when running a shell script, for instance), and ~/.profile is called on every login.

So I recommend you to write . ~/.bashrc command in your ~/.profile file, and this command will execute the bashrc file every time you login.

share|improve this answer
when .profile get executed on login it automatically execute the .bashrc file. – arun rana Sep 24 '12 at 12:53
so .bashrc gets executed indirectly at every login – arun rana Sep 24 '12 at 12:54

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.