I'm using Linux Mint. My login shell (cat /etc/passwd | grep myUserName
) is bash.
After I start my graphical desktop environment and run a terminal emulator from it, I can see that .bash_profile
is not sourced (environment vars that are export
ed in it are unset). But if I log in from a text console (ctrl+alt+F1) or manually run bash -l
from the terminal emulator, .bash_profile
works fine.
Am I wrong when I think that .bash_profile
should be sourced when X starts and all export
'ed vars should be available in the terminal, running from X?
P.S. Placing everything in .bashrc
and sourcing it from .bash_profile
is not good idea (https://stackoverflow.com/questions/902946/): environment stuff should be sourced only once.
Best Answer
The file
~/.bash_profile
is read by bash when it is a login shell. That's what you get when you log in in text mode.When you log in under X, the startup scripts are executed by
/bin/sh
. On Ubuntu and Mint,/bin/sh
is dash, not bash. Dash and bash both have the same core features, but dash sticks to these core features in order to be fast and small whereas bash adds a lot of features at the cost of requiring more resources. It is common to use dash for scripts that don't need the extra features and bash for interactive use (though zsh has a lot of nicer features).Most combinations of display manager (the program where you type your user name and password) and desktop environment read
~/.profile
from the login scripts in/etc/X11/Xsession
,/usr/bin/lightdm-session
,/etc/gdm/Xsession
or whichever is applicable. So put your environment variable definitions in~/.profile
. Make sure to use only syntax that dash supports.So what should you put where?
A good
.bash_profile
loads.profile
, and loads.bashrc
if the shell is interactive.In
.profile
, put environment variable definitions, and other session settings such asulimit
..bashrc
, put bash interactive settings such as aliases, functions, completion, key bindings (that aren't in.inputrc
), …See also Difference between Login Shell and Non-Login Shell? and Alternative to .bashrc.