Written by , Updated on April 12, 2020

A shell is an important layer of Linux architecture. Shell is an interface which takes input from Users and sends instructions to the Kernel, Also takes the output from Kernel and send the result back to output shell.

In this tutorial, we use Bash shell for the examples. Basically a shell is of two types, Login Shell and Non Login Shell. Every shell run some set of predefined scripts to configure shell environments.

Login Shell

A Login shell is created after a successful login of user. For example, when you login t a Linux system via terminal, SSH or switch to user with “su -” command.

When a login shell start, it runs a set of predefined script to configure shell environment. To identify the login shell, run the below command on terminal.

echo $0

If you get the result like “-bash” or “-su” means, you are on login shell. Make sure it has hyphen (-) as prefix.

A Login Shell executes following scripts:

  • Login shell executes /etc/profile
  • /etc/profile executes all scripts in /etc/profile.d/
  • Then executes users ~/.bash_profile
  • ~/.bash_profile executes users ~/.bashrc
  • ~/.bashrc executes /etc/bashrc

Non Login Shell

Non Login Shell is the shell, which is started by the login shell. For example, A shell which you started from another shell or started by a program etc.

A non login shell executes the following script to set the shell environment.

  • Non login shell first executes ~/.bashrc
  • Then ~/.bashrc executes /etc/bashrc
  • /etc/bashrc calls the scripts in /etc/profile.d

Check Login vs Non Login Shell

To find the current shell is login shell or non login shell simply run the below command. See the results and find the different between them.

echo $0

Login shell output will be -bash or -su.

Non logins shell output will be bash or su

What is the difference between Login and Non-Login Shell bash linux Linux Tutorials shell