Which shell am I using and finding shells installed on Unix

So, you have questions like, which shell am I using? Which is my default shell? How to find shells installed on your Unix or Linux system. Let’s discuss all these questions and try to answer them.

Before that, let’s understand what is a shell in UNIX.

Unix Shells

Unix is a multi-user and multi-tasking Operating System. It has a unique and powerful program called Shell.

Shell is a command interpreter that interprets the commands entered by you, runs against Unix/Linux Kernel, and provides the result on the standard output device. There are many shells developed since Unix came into existence.

Below is the list,

  • Bourne Shell – sh
  • C Shell – csh
  • T Shell – tcsh
  • Korn Shell – ksh
  • Bourn-again Shell – bash
  • Dash Shell
  • Z shell

Just head on to this Wikipedia article for details.

How to find shells installed in Unix System?

Unix and Linux systems may have more than one shell installed. Run more or cat command on /etc/shells to find all the shells installed on Unix System(show below).

$ cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh
/bin/ksh

You get a list of all shells on the terminal.

Which Shell am I Using?

Unix creates all required configuration and setup when a user is created. Run grep <user> /etc/passwd to know the shell which you are using when you log in to Unix or Linux operating system.

Where <user> – login user name.

The below example answers the question which shell you are using.

$ grep atechtown /etc/passwd
atechtown:x:1000:1000::/home/atechtown:/bin/sh

Here, the default is Bourne – sh. Another way is by using the $SHELL variable. This variable is set with the default name as soon as you log in.

Just display the content of the variable using the echo command to find out the default shell.

$ echo $SHELL
/bin/sh

Which Shell am I running at this moment?

You can always switch the shell by typing the respective shell name on the terminal prompt. At any point in time, if you want to know which is the current shell, you can run the following commands on the terminal window.

 $ ps -p $$
   PID TTY          TIME CMD
1505 pts/0   00:00:00  sh

Now let’s change it to bash.

$ ps -p $$
  PID TTY TIME CMD 
1505 pts/0 00:00:00 bash

What is the value of $SHELL now?

$ echo $SHELL
/bin/sh

$SHELL value does not change even you change the shell on the terminal, it always stores default.

Another way, just echo the content of $0 to check the current shell in the Linux system.

$ echo $0
bash

Changing the Default shell

chsh command allows you to change the default shell. Open the terminal and run below on the command line.

$ grep atechtown /etc/passwd
atechtown:x:1000:1000::/home/atechtown:/bin/sh

$ chsh
password:
Changing the login shell for atechtown
Enter the new value, or press ENTER for the default
      Login shell [/bin/sh]: /bin/bash  

$ grep atechtown /etc/passwd
atechtown:x:1000:1000::/home/atechtown:/bin/bash

Now /bin/bash is your new shell.

Summary

I hope we answered all the questions you had for Unix/Linux Shells.

Share This: