2

This question already has an answer here:

I'm running Ubuntu, with Gnome3 as my desktop manager. While debugging some initialization issues (the usual confusion over bash_profile, bashrc, etc.), I found that given the following files,

# ~/.bash_profile
export X=x

# ~/.profile
export Y=y

if I reboot, log in, and start a shell, it seems like ~/.bash_profile was never sourced:

$ echo ${X-var_not_set}
var_not_set
$ echo ${Y-var_not_set}
y

I'm using Gnome terminal, running non-login shells (the default), so it makes sense that ~/.bash_profile would not be sourced when I start a shell in the terminal emulator, but I thought ~/.bash_profile would have been sourced when I originally logged in at the graphical login screen.

I'm unclear whether that login screen is the domain of the OS (Ubuntu), the graphical shell (Gnome), or something else (display manager?), and thus, what initialization files are run.

The Bash manual says that ~/.bash_profile will be used instead of ~/.profile if it's present, but the above behavior seems to contradict that.

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, 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.

My best guess is that the graphical login has nothing to do with Bash (is this related to dash shell?), and as such, it executes ~/.profile. Is that the case, or is there more to this that I'm misunderstanding?

marked as duplicate by don_crissti, Stephen Rauch, ivan, Community Oct 15 '17 at 22:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Yeah, the answer to that question totally covers this one. Good call. – ivan Oct 15 '17 at 22:43

Browse other questions tagged or ask your own question.