When you log in to your GUI session, the script that sets up your session is executed in a non-interactive login shell. It reads /etc/profile
, your ~/.[bash_]profile
etc. and sets up your environment for the whole GUI session. Then the shell executes a script that will start your desktop environment. Effectively, that shell will be SHLVL 1 for your session.
The X session setup script may actually exec
the last command that actually fires up the desktop environment. That explains why you can't find a shell process in the process tree view for your session (ps xf
): that shell is done its job and gone, only its environment variables (and any other inheritable settings, like custom ulimits) are inherited by the main process of the desktop environment, which passes them on to all its child processes. This way, a program started from a desktop menu will also have any environment variables you may have set in your .bash_profile, and so will work as you'll expect.
It is also possible to set up the terminal windows to start up as login shells, so they would be SHLVL 1. At least KDE on Debian seems to do it that way.