What is Shell?
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.
The shell provides a common interface to a number of tools in the system. For example, if the shell needs to perform an action that requires a system command, it will search for the command and then execute it on behalf of the user.
What are the different types of shells?
A non-login shell or a login shell is used in this example, which employs the Bash shell. Shells execute pre-configured scripts to establish their environments.
The shell plays an important role in the Linux operating system architecture. It receives input from users and sends instructions to the kernel, and it receives output from the kernel and returns it to the user.
A shell executes a predetermined set of scripts to configure its environment. The Bash shell, for example, is used.
What is a Login Shell in Unix/Linux System?
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
~/.bashrc
invokes/etc/bashrc
What is a Non-Login Shell in Unix/Linux System?
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
Checking whether a shell is a login or non-login shell
To find whether the current shell is a login shell or a non-login shell simply run the below command. See the results and find the difference between them.
echo $0
Login shell output will be -bash or -su.
Non logins shell output will be bash or su
Conclusion
A Bash shell can be either a login shell or a non-login shell. Both types of shells are invoked with different environment settings. You can easily identify whether a shell is a login shell or a non-login shell with the echo $0
command.
In simple terms, when we log in to a Unix-like system with a user, the first shell is the login shell.
1 Comment
Good info Rahul. Thanks