Why might one add ~/.profile to ~/.bash_profile?
.profile
and .bash_profile
are identical in terms of when they're meant to be executed: they're executed when you log in. The difference is that only bash runs .bash_profile
; Bourne-style shells (dash, ksh, etc.) runs .profile
. Bash itself runs .profile
if .bash_profile
doesn't exist.
Even if you have bash as your login shell, .profile
is often the one that's executed when you log in in graphical mode — many distributions set up the X session startup script to run under sh
and load .profile
.
Hence the advice to use .profile
instead of .bash_profile
to do things like defining environment variables. Unless you absolutely need bash-specific features, just put everything in .profile
. But even if you do, there's a reason to keep a .bash_profile
, which is that when bash loads it, it doesn't load .bashrc
, even if it's interactive. Hence, for most people, ~/.bash_profile
should consist of these two lines:
. ~/.profile
case $- in *i*) . ~/.bashrc;; esac
You should not run xmodmap
from .profile
. This isn't executed when you open a new shell, but it is executed, for example, when you log in remotely with SSH with X11 forwarding. Unfortunately, there's no standard file that's loaded when you log in in graphical mode. Debian loads ~/.xsessionrc
(I think this applies to all display managers, except Gdm which loads ~/.xprofile
instead); other distributions have different setups. If you need cross-distribution portability, it may be easier to configure your desktop environment to execute xmodmap
when it starts. If all you're doing is swapping CapsLock and Ctrl, this can be done with XKB settings that most modern desktop environments provide an interface to.
Remember that bash(1) is the only shell that reads .bash_profile
, other Bourne shell derivatives just read .profile
. If you sometimes use another shell, you'd want to keep .profile
.