According to the answer to What are login and non-login shells? on Ask Ubuntu, GNOME Terminal is a type of non-login shell.
As pointed out in the excellent book, A Practical Guide to Fedora and Red Hat Enterprise Linux, 6th Edition:
an interactive non-login shell executes commands in the ~/.bashrc file. The default ~/.bashrc file calls /etc/bashrc.
As a result, /etc/profile
won't be processed in a non-login shell. However, I found that I have appended the java home path to the PATH
variable and, when I use GNOME Terminal and issue the command java
, everything goes fine. Also, the value of the PATH
variable is the same as the value I defined in /etc/profile
.
In view of the above-mentioned facts, there is a conflict, what’s wrong with my understanding?
Best Answer
When you log in to your x session via a display manager or in a tty,
/etc/profile
is (usually - apparently it is being in your case, though some graphical shells do not read it) sourced by your shell program. After that, a local file (I'm assuming you're using bash here)~/.bash_profile
,~/.bash_login
or~/.profile
will be sourced, and any environment variables defined here will override/etc/profile
for the current user. This environment is inherited by any shell you open within the session. This is why we can define environment variables, such as your PATH, in these files.When you open gnome-terminal, yes by default that starts a non-login shell, but it inherits your user environment already loaded from the login shell or graphical shell. Since
~/.bashrc
is sourced when starting an interactive shell (eg opening gnome-terminal), it may be used to override some elements of the environment (such as PS1).(gnome-terminal itself is an application, not a shell)