aliases in .profile don't work?

MR ZenWiz mrzenwiz at gmail.com
Thu Dec 9 00:01:38 UTC 2010


On Wed, Dec 8, 2010 at 3:19 PM, Marius Gedminas <marius at pov.lt> wrote:
> On Wed, Dec 08, 2010 at 02:46:25PM -0800, Knute Johnson wrote:
>> Anybody know why putting an alias in ~/.profile doesn't work but putting
>> it in ~/.bash_aliases does?
>
> ~/.profile is sourced for login sessions only (both ssh logins and gdm
> logins, the latter thanks to Ubuntu's /etc/gdm/Xsession).  Aliases
> aren't exported via the environment, so any new shell sessions -- such
> as those you get by opening a terminal window -- do not inherit them.
>
> ~/.bash_aliases is sourced for every new shell session.
>
This is not standard behavior - there is no special handling of
~/.bash_aliases built into bash.

When bash is invoked as a login shell, it first reads /etc/profile if
that file exists, then it looks for the first of ~/.bash_profile,
~/.bash_login and ~/.profile, in that order, to execute whatever it
finds there.

Interactive bash shells that are not login shells (i.e., scripts or
direct invocations from the command line) read and execute
/etc/bash.bashrc and then ~/.bashrc, if these files exist.

These are the places to look, in that order, to see what's happening.

I generally prefer to have a consistent environment for execution, so
I set my .bash_profile to source .bashrc and have all my settings in
.bashrc.  I keep my aliases and functions in separate files that my
.bashrc sources explicitly.

(Above taken directly from 'man bash' on Maverick.)

>> ~/.bash_profile or ~/.bash_login do NOT
>> exist.  Adding a change to the PATH works just fine in ~/.profile.
>
> PATH is usually exported via the environment, so setting it in ~/.profile
> is sufficient.
>
True, and this will also affect most other shells as well, as
~/.profile is more or less universal (except for csh).




More information about the ubuntu-users mailing list