Put everything in .bashrc
and then source .bashrc
from .profile
From the bash man page (on OS X 10.9):
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc
The above text is why everything is put in .bashrc
. However, there's a bit different behavior when you're dealing with a login shell. Again, quoting from the man page:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
.profile
is read for login shells, but .bashrc
is not. Duplicating all that stuff in .bashrc
is bad™ so we need to source it in .profile
in order for the behavior to remain consistent.
However, you don't want to source .bashrc
from .profile
unconditionally. Please see the comments and other answers for additional details.
6this question should not be marked as duplicate the reason is .profile is not available in the added question. – Premraj – 2015-12-20T02:25:00.330
Ans: http://serverfault.com/q/261802/270464
– Premraj – 2015-12-20T02:26:06.000