Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Tutorials»What is the difference between Login and Non-Login Shell?

    What is the difference between Login and Non-Login Shell?

    By RahulAugust 3, 20223 Mins Read

    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.

    Advertisement

    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:

    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
    5. ~/.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.

    1. Non login shell first executes ~/.bashrc
    2. Then ~/.bashrc executes /etc/bashrc
    3. /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

    difference between login shell vs non login shell

    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.

    bash linux shell
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    An Introduction to the “./configure” Command: Compiling Source Code in Linux

    Getting Started with Linux Command line: The Beginning

    Backing Up Your Linux System with Rsync: A Step-by-Step Guide

    View 1 Comment

    1 Comment

    1. Jayesh on April 25, 2020 6:06 am

      Good info Rahul. Thanks

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.