Possible Duplicate: What's the difference between .bashrc, .bash_profile, and .environment?
It seems that if I use
alias ls='ls -F'
inside of .bashrc on Mac OS X, then the newly created shell will not have that alias. I need to type bash
again and that alias will be in effect.
And if I log into Linux on the hosting company, the .bashrc
file has a comment line that says:
For non-login shell
and the .bash_profile
file has a comment that says
for login shell
So where should aliases be written in? How come we separate the login shell and non-login shell?
Some webpage say use .bash_aliases
, but it doesn't work on Mac OS X, it seems.
From the bash manpage:
Thus, if you want to get the same behavior for both login shells and interactive non-login shells, you should put all of your commands in either
.bashrc
or.bash_profile
, and then have the other file source the first one..bash_profile
is loaded for a "login shell". I am not sure what that would be on OS X, but on Linux that is either X11 or a virtual terminal..bashrc
is loaded every time you run Bash. That is where you should put stuff you want loaded whenever you open a new Terminal.app window.I personally put everything in
.bashrc
so that I don't have to restart the application for changes to take effect.Check out http://mywiki.wooledge.org/DotFiles for an excellent resource on the topic aside from
man bash
.Summary:
~/.bash_profile
or~/.profile
is read and executed. Since everything you run from your login shell inherits the login shell's environment, you should put all your environment variables in there. LikeLESS
,PATH
,MANPATH
,LC_*
, ... For an example, see: My.profile
~/.bashrc
, not/.profile
or~/.bash_profile
, for this exact reason, so in there define everything that only applies to bash. That's functions, aliases, bash-only variables like HISTSIZE (this is not an environment variable, don't export it!), shell options withset
andshopt
, etc. For an example, see: My.bashrc
~/.bashrc
but only~/.profile
or~/.bash_profile
, so you should source that one manually from the latter. You'll see me do that in my~/.profile
too:source ~/.bashrc
.The reason you separate the login and non-login shell is because the
.bashrc
file is reloaded every time you start a new copy of Bash. The.profile
file is loaded only when you either log in or use the appropriate flag to tell Bash to act as a login shell.Personally,
PATH
setup into a.profile
file (because I sometimes use other shells);.bashrc
file;I put this
in my
.bash_profile
file.Oh, and the reason you need to type
bash
again to get the new alias is that Bash loads your.bashrc
file when it starts but it doesn't reload it unless you tell it to. You can reload the.bashrc
file (and not need a second shell) by typingwhich loads the
.bashrc
file as if you had typed the commands directly to Bash.