Gangmax Blog

Login Shell & Non Login Shell

In “gnome-terminal” profile, there is an option “Run command as a login shell”. You can enable/disable it. But what is the difference?

The answer comes from here, here and here.

In short, the behavior is:

  1. “bash” started as an interactive login shell: reads “~/.profile”.

  2. “bash” started as an interactive non-login shell: reads “~/.bashrc”.

Some explanation of the terminology:

  1. An interactive shell is a shell with which you can interact, that means you can type commands in it. Most shells you will use are interactive shells.

  2. A non-interactive shell is a shell with which you cannot interact. Shell scripts run inside non-interactive shells.

  3. A login shell is the shell which is started when you login to your system.

  4. A non-login shell is a shell which is started after the login process.

Most shells you see are interactive non-login shells. This is especially true if you are running a graphical environment like gnome, because then gnome is the “login shell”. Any bash session started inside gnome is a non-login shell. If you want to see a real interactive login shell then go to a virtual console (using “Ctrl+Alt+F1”) and then log in using your username and password. That is a real interactive login bash shell. You can go back to the graphical shell using “Ctrl+Alt+F7”.

There is an option “–login” which will make bash behave as if it is a login shell even if started after your have logged in. Configuring gnome-terminal to start bash as a login shell means it will start bash using the “–login” option.

You should put stuff which is bash specific in “/.bashrc” and stuff which is not bash specific in “/.profile”. For example “PATH” goes in “/.profile” and HISTCONTROL goes in “/.bashrc”.

Note that “/.profile” is not bash specific. Other text based shells (for example sh or ksh) and graphical shells (gnome) also read “/.profile”. That is why you should not put bash specific stuff in “~/.profile”.

Comments