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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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)
Method 2
short: no
long: gnome-terminal is a terminal. You run a shell in a terminal. You can run either type of shell (login or not) in a terminal (though gnome-terminal makes it harder than other terminals).
Further reading:
- Bug 71368: gnome-terminal “update utmp/wtmp” option doesn’t work when not using gdm
- Why isn’t gnome-terminal a login shell
- Configure gnome-terminal to start bash as a login shell, doesn’t read .bashrc
Method 3
Try this, it works in BASH.
shopt -q login_shell && echo " <<< It's a Login Shell >>> " || echo " <<< It's "NOT" a Login Shell >>> "
By the way, Gnome Terminal is just a terminal emulator(an application program) that uses shell(more specifically BASH).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0