Shell is a command interpreter or a program that reads and interprets commands issued to it by the user. The shell performs basic commands such as running programs, inputting text, and printing output. It is also responsible for handling errors and other situations that require user intervention. A shell can be used to automate existing tasks or to create new ones entirely.

Login Shell

When a user successfully logs in to a Linux system via terminal, SSH, or switches to a user with the su - command, a Login shell is created.

When a login shell starts, it executes a set of pre-configured scripts to set up the environment. You may run this command on the terminal to discover which shell you are using.

echo $0

If the result is -bash or -su, you are on the login shell. Be certain that it has a hyphen (-) as a prefix.

The following scripts are executed by the Login Shell:

  1. Login shell invokes /etc/profile
  2. /etc/profile invokes scripts in /etc/profile.d/*.sh
  3. Then executes users ~/.bash_profile
  4. ~/.bash_profile invokes users ~/.bashrc
Non-Login Shell

A non-login shell is started by a login shell. For example, a shell that you start from another shell or from a program is a non-login shell.

A shell that is not used to log in to the system executes the following script to set the shell environment.

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

To find whether the current shell is a login shell or a non-login shell simply run the below command.

echo $0

Login shell output will be -bash or -su.

Non-login shell output will be bash or su