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:
- Login shell invokes
/etc/profile
/etc/profile
invokes scripts in/etc/profile.d/*.sh
- Then executes users
~/.bash_profile
~/.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.
- Non login shell first executes
~/.bashrc
- Then
~/.bashrc
executes/etc/bashrc
/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