How do I find out what shell I am using on Linux/Unix?

Both Linux and Unix provides various shell out of the box. One can find bash (Bourne Again shell), ksh (Korn shell), csh (C shell)/tcsh (TC shell), sh (Bourne shell) and more installed by default. However, how do you check which shell am I using? What is the best way to find out what shell I am using on Linux? The echo $SHELL is not so reliable. This page explains how to find out which shell I am using at a Linux, MacOS, FreeBSD, or Unix-like systems.

How can I find out what shell I am using?

The following echo command or printf command should work:
echo "$SHELL"
printf "My current shell - %s\n" "$SHELL"
Please note that $SHELL is the shell for the current user but not necessarily the shell that is running at the moment. Try the following examples

echo "My current shell is $SHELL ($0)"
ksh   ## start a new shell ##
echo "My current shell is $SHELL ($0)"
echo $SHELL

Find out what shell I am using on Linux or Unix
Hence, I recommend using the following syntax to check which shell you are using.

How do I check which shell am I using?

Here is another old good Unix trick. Use the ps command with -p {pid} option. The following command selects the processes whose process ID numbers appear in pid. Use the following command to find out which shell you are in:
ps -p $$
Sample outputs:

  PID TTY          TIME CMD
 5217 ?        00:00:00 bash

So what is a $ argument passed to the -p option? Remember $ returns the PID (process identification number) of the current process, and the current process is your shell. So running a ps on that number displays a process status listing of your shell. In that listing, you will find the name of your shell (look for CMD column).
ps -p $$
Sample outputs:

  PID TTY          TIME CMD
6453 pts/0    00:00:00 csh

From my Linux box:
ps -p $$
Sample outputs:

  PID TTY          TIME CMD
5866 pts/0    00:00:00 bash

You can store your shell name in a variable as follows :
MYSHELL=`ps -hp $$|awk '{echo $5}'`
Please note those are backquotes, not apostrophes. Or better try out the following if you have a bash shell:
MYSHELL=$(ps -hp $$|awk '{echo $5}')
Another option is as follows:
echo $0
printf "%s\n" $0
Sample outputs from the above commands:

Fig.01: Linux check which shell am I using

Fig.01: Linux check which shell am I using

We can also use the readlink command as follows to print resolved symbolic links to actual shell on Linux:
readlink /proc/$$/exe
Will show:




How do I check how many shells are installed on my Linux box?

The /etc/shells is a text file which contains the full pathnames of valid login shells. Type the following [nixmd name=”cat”] to see list how many shells are installed on your Linux or Unix box:
cat /etc/shells

Linux or Unix check how many shells are installed

Use /etc/shells file to check how many shells are installed on your system

Okay, so when I open the Terminal app, which shell is opened by default?

Your default shell is defined in /etc/passwd file. So try the following grep command:

grep "^$USER" /etc/passwd
awk -F: '/vivek/ { print $7}' /etc/passwd

When I open a terminal, which shell is opened by default on Linux
It looks like /bin/bash shell is my default shell. Want to change your default shell? Read “change shell in Linux or Unix” FAQ page for more info. Let us summarize all command once again.

How to check which shell am I using:

Use the following Linux or Unix commands:

  1. ps -p $$ – Display your current shell name reliably.
  2. echo "$SHELL" – Print the shell for the current user but not necessarily the shell that is running at the movement.
  3. echo $0 – Another reliable and simple method to get the current shell interpreter name on Linux or Unix-like systems.
  4. readlink /proc/$$/exe – Another option to get the current shell name reliably on Linux operating systems.
  5. cat /etc/shells – List pathnames of valid login shells currently installed
  6. grep "^$USER" /etc/passwd – Print the default shell name. The default shell runs when you open a terminal window.
  7. chsh -s /bin/ksh – Change the shell used from /bin/bash (default) to /bin/ksh for your account


Sometimes things are not easy as they seem, and this page is the perfect example of it. I hope you found the suggestion useful when it comes to checking your current running shell. Bash users can display shell version by typing the following command:
$ bash --version
Here is what I got from my Ubuntu Linux 20.04 LTS desktop:

GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 35 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
35 comments… add one
  • Akram Mar 12, 2008 @ 11:51

    thanks this is what i looking for

  • Paul Harper Jun 30, 2008 @ 16:49

    you can also use
    echo $0

    • PaulD Feb 14, 2013 @ 6:48

      This is the only method listed here that works for me (Mac OS X).

    • ania salve Dec 4, 2013 @ 10:39

      Thanks .. this was veryuse ful..echo $0

      • Jimm May 30, 2016 @ 10:10

        echo $0 – works for Raspberry Pi on Raspbian

  • maki May 17, 2010 @ 16:22

    -hp might not work. Also, echo?

    ps h -p $$ | awk '{print $5}'

  • ashwin Jun 8, 2010 @ 16:22

    You can also find this out from et/passwd file :

    Command to run:
    # cat /etc/passwd

    • Abhisek Aug 10, 2012 @ 11:57

      Sure, does this give accurate result?

      • lexlythius Sep 5, 2012 @ 15:29

        No, it tells you the *default* shell for every user, not the one you are actually using in your current session.


        ps h p $$
         6710 pts/0    S      0:00 /bin/bash

        or as others said:

        ps h p $$ | awk '{ print $NF }'

        If you only need the shell name and not its executable full path:

        basename $( ps h p $$ | awk '{ print $NF }' )
    • DM6 Oct 6, 2020 @ 10:36

      No. it will just list default login shell for each Unix user. Hence, the blog post.

  • lee murray Jul 8, 2010 @ 11:58

    exactly what i was looking for. thanks

  • Suneelm Jul 21, 2010 @ 10:16

    Thanks ..

    • ujjal Dec 21, 2011 @ 12:29

      you can also use
      ps | grep $$

  • gitterrost4 Sep 19, 2010 @ 7:42

    Thanks for this.
    But the last sentence…

    Or better try out following if you have a bash shell:
    MYSHELL=$(ps -hp $$|awk '{echo $5}')

    If you have a bash shell, couldn’t you just do

    • Victor Feb 7, 2012 @ 13:09

      LOL, just what I was thinking. ^^

  • akshay Oct 19, 2010 @ 11:37

    ps -p $$
    echo $0

    thanks a lot!

  • john fuller Oct 27, 2010 @ 18:33

    I noticed that, command such as; ps -$$, echo $SHELL, echo $0, printenv will print the current shell, but In case you have temperoraly changed your shell, these commands will not show the changes, unless you log out and log In. Whereas, cat /etc/passwd file will show the change mmediately without loging out.

    For ex: At the current shell (ex-/bin/bash), if you type ‘chsh’ and then enter /bin/tcsh, it will change the shell to ‘tcsh’, but the cmds mentioned above will still be reporting the old shell that is /bin/bash, unless you logout. But, /et/passwd file will show the changes immediately.

    • Giuseppe Bertone Aug 30, 2011 @ 11:01

      Hi John,

      ps -p $$


      echo $0

      always return the current shell, even from a sub-shell because they print the current process.

      The /etc/passwd file is simply a file and then it does not store the current user shell but the login shell. In your example, you are using the Change login shell (chsh) to actually change the shell automatically launched at your login, and this is why the change is immediately visible in the /etc/passwd file.

    • Raghavendra Oct 5, 2012 @ 15:22

      I verified the output and it seems what you have said is totally opposite.. i.e, when u change the shell the changes are updated in ps -$$, echo $shell, echo $0 , and printenv. But not /etc/passwd file

  • san Jan 5, 2011 @ 17:53

    you can also use

    ps -u

  • Tim Jowers Feb 24, 2011 @ 20:37

    $ bash
    [a148503@wuvra99a0219 logs]$ uname -a
    Linux wuvra99a0219 2.6.18-194.8.1.el5 #1 SMP Wed Jun 23 10:52:51 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

    $SHELL is the only thing remaining as ksh:

    [a148503@wuvra99a0219 logs]$ ps -$$
    18336 pts/13 S 0:00 bash
    [a148503@wuvra99a0219 logs]$ echo $SHELL
    [a148503@wuvra99a0219 logs]$ echo $0

  • cindy Apr 3, 2011 @ 0:48


  • CRP Sep 2, 2011 @ 19:51

    This is not 100% accurate.

    • echo $SHELL and other similar methods print the name the current shell is called in the current environment.
    • sh –version, on the other hand, prints the version of the default shell
    • If you combine them, you can spawn another process, running the same shell as the parent, and ask it what is its version.

    Example (note how my shell is given the name “csh”, but it is really a tcsh):

       [me@localhost ~]$ echo $SHELL
       [me@localhost ~]$ sh --version
        GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
        Copyright (C) 2005 Free Software Foundation, Inc.
       [me@localhost ~]$ $SHELL --version
        tcsh 6.14.00 (Astron) 2005-03-25 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec
    • Abhisek Aug 10, 2012 @ 12:01

      So how to get the exact 100% accurate result?
      How to know the current shell I’m using?

  • Ajit Jun 6, 2012 @ 11:41

    Nice tricks.

  • jim Aug 8, 2012 @ 15:43

    Hi, I have a problem which cannot be solved with the methods mentioned above. I need to find out within a bash script from which shell it was executed. If I use the methods above, I of course get always bash, since the executed script is a bash script. Does anybody have an idea?
    Cheers, Jim

  • octy Oct 24, 2012 @ 18:38

    Just a note: why use awk if
    ps -p $$ -o ucomm=
    does the trick and supported by most *nixes?

  • octy Oct 24, 2012 @ 18:40

    Just a note: why use awk, if
    ps -p $$ -o ucomm=
    does the trick?

  • shubha Dec 16, 2013 @ 2:44

    Which of the following command displays your login shell in Bash shell
    a) $SHELL b) echo$ Bash c) echo$ 0 d) $0

  • shubha Dec 16, 2013 @ 2:46

    Which of the following command displays your login shell in Bash shell
    a)$ SHELL
    b)echo $Bash
    c)echo$) 0
    d) $ 0

  • Skinnx86 Feb 22, 2015 @ 22:14

    When echo $SHELL does work for you, try echo $$ $SHELL. Due to $$ representing the {pid} column it will append the pid to the output; include a space and it becomes, more, human readable.

  • norris Sep 10, 2015 @ 8:59

    Is this acceptable:
    ps -p $$ > /dev/null; echo $0

  • Peter Keller Apr 28, 2016 @ 16:53

    Old question, but here is an answer. You need to get the current process’s parent id, and give that as the argument to ‘ps -p‘. You can do it like this:

    ps -p `ps -o ppid --no-headers -p $$`

    If you want to convince yourself that you are getting the right answer, you can see the parent process id in a more human readable form with:

    ps -O ppid $$

    N.B. Lower case letter ‘o’ in the first command, upper case letter ‘O’ in the second one.

  • Jordan Jul 13, 2016 @ 22:24

    When I was learning the Unix shell using bash, I learned that you can just type in the name of the shell and the output will tell you. For example, when I type “bash” it prints out “bash-3.2” which tells that I am using the bash shell.

  • Aimi Oct 6, 2020 @ 10:39

    I wanted to check which shell I am using and your tutorial solved my problem.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum