How to check what shell I’m using on Linux

The shell on a Linux system is the layer that interprets the commands being executed by the user, and translates them into a language that the operating system can understand. The Bash shell is the default one in Linux, and typically what all users become familiar with first. But there are a lot of other shells that can be used, too; like sh, zsh, ksh, csh, and tcsh, to name a few.

Knowing what shell you are currently using is important, since each one will interpret commands a little differently. Some of them expect a different syntax than others. For example, a Bash script may work perfectly fine in Bash, but produce errors when executed with the sh shell. In this tutorial, we will show you how to check what shell you are using on Linux.

In this tutorial you will learn:

  • How to check what shell you are currently using
  • How to check a user’s default shell
  • How to generate a list of available shells on the system
  • How to change to a different shell
How to check what shell I'm using on Linux
How to check what shell I’m using on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to check what shell I’m using – example commands



DID YOU KNOW?
Linux user accounts can be configured to log in to a particular shell by default (for example, with the usermod command), or they can switch to a different shell after being logged in.

Let’s see how to check our current shell, display a list of usable shells, and switch to a different shell in Linux.

  1. First, let’s check what shell we are currently using. We can rely on the SHELL environment variable for this by executing the following command:
    $ echo $SHELL
    /bin/bash
    
    Checking what shell we are currently using in Linux
    Checking what shell we are currently using in Linux

    The command shows us that we are using the Bash shell, which is located at /bin/bash.



  2. Next, let’s see what our default shell is by looking inside of the /etc/passwd file. We will check specifically for user linuxconfig by piping to the grep command.
    $ cat /etc/passwd | grep linuxconfig
    
    The /etc/passwd file shows us that /bin/bash is our default configured shell
    The /etc/passwd file shows us that /bin/bash is our default configured shell

    The final field in the output will show what shell a user is using by default when they log in.

  3. We can get a full list of the shells installed on the system by executing the following command. Any of these are available to use, except some, like the /sbin/nologin shell, which serve a specific purpose and are not meant to be usable by people.
    $ cat /etc/shells
    
    Checking which shells are available for use on our Linux system
    Checking which shells are available for use on our Linux system
  4. Now, let’s see how we can change to a different shell, in case we recognize one from the list above that we would like to use instead of our current one. For this, we can just execute the full path of the shell we want to use. This command will log us into the sh shell.
    $ /bin/sh
    

Closing Thoughts




In this tutorial, we saw how to check what shell you are currently using on a Linux system. Experienced users may come to appreciate some of the functions offered outside of the Bash shell, and have the desire to switch every once in a while. Being able to quickly identify and switch between shells allows you to get the most out of your Linux command line experience, and always choose the right tool for the job.



Comments and Discussions
Linux Forum