These are the contents of the stock ~/.profile
that came with my 13.10 (commented lines removed):
if [ -n "$BASH_VERSION" ]; then
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
This is inherited from Debian but why did Canonical decide to keep it? As far as I know, it's not the standard *nix way and I have seen various systems where this did not happen, so I assume they must have had a good reason to. This can cause unexpected behavior when running login shells (such as when sshing into the machine for example) where the user would not expect to have ~/.bashrc
sourced.
The only benefit I can think of is to not confuse the user with many startup files and allow them to edit .bashrc
alone and have that read irrespective of shell type. That, however, is a dubious benefit since it is often useful to have different settings for login and for interactive shells and this blocks you from doing so. Also, login shells are very often not run in a graphical environment and that can cause errors and warnings and problems (oh my!) depending on what you've set in those files.
So why does Ubuntu do this, what am I missing?
This is an upstream decision coming from Debian. The rationale for it is explained in this very nice wiki post, of which the following is an excerpt. The executive summary is "to ensure that GUI and non GUI logins work in the same way":
This is Ubuntu's standard behaviour,
~/.bashrc
is user-level per-interactive-shell start up file. When you open a terminal basically you start a non-login, interactive shell which reads~/.bashrc
and contents of~/.bashrc
get sourced and exported into your current shell environment. It helps one to obtain all his user defined shell variables and functions in the current shell. Also you could find lines like thisto obtain user defined aliases in current shell environment.
This is important in order to provide good user experience also. For example one could store proxy credential in
.bashrc
, unless it get sourced none of terminal applications (viz,ping
,wget
,curl
,lynx
etc.) will work properly. Or you have to provide the proxy credentials every time you open a terminal.Besides Ubuntu's default
.bashrc
contains many user friendly aliases (forls
andgrep
to print colourized output), many new definitions for different shell variables which increases user experience.But in case of your ssh login, or login in virtual console, you basically get an interactive login shell. There the shell initiation file is
~/.profile
. Hence unless you source~/.bashrc
you miss all those helpful settings in your.bashrc
. That is why Ubuntu's default~/.profile
source~/.bashrc
Case to avoid
~/.profile
form inside~/.bashrc
at the same time when~/.bashrc
is being sourced from~/.profile
. It will create an infinite loop of situation and as a result your terminal prompt will be suspended unless you hit Ctrl+C. In such a situation if you put a line in your~/.bashrc
Then you could see that the file descriptor is stopping when you open a terminal.