How to Find Which Shell You Are Using on Linux

Which Shell am I using in Linux? Is that even a question? Of course, it is. There are several shell available for Linux systems. Some of the most popular ones are:

  • bash
  • ksh
  • zsh
  • tcsh

You may wonder this in a few situations.

For example, if you log into a Linux system not known to you, you may wonder which shell is being used by default. If you frequently change shell in Linux, you might wonder which shell you are using at the moment.

Let me show you various Linux commands to find out which shell you are using.

Find out which shell you are using in Linux

Now there is no command that will give you this output with 100% accuracy for all the shells. But these commands should be accurate for most of the shells.

Method 1

You can use the special shell parameter $$. “$$” indicates the process id of the current instance of the shell you are running. This is a read-only parameter and cannot be modified.

If you try to see the process information, it should show you the process name i.e. the shell here.

ps -p $$

The output should be like this:

PID TTY          TIME CMD
15012 pts/0    00:00:00 zsh

Method 2

You can also use $0. $0 can be the name of the shell or the name of shell script. When it is used inside a shell script, it denotes the name of the script.

But if you use it in a shell without filename, it will show the name of the shell.

echo $0

The output will simply have the name of the shell:

echo $0
bash

Method 3

You can also use the pstree command. pstree means process tree and it shows all the running processes as a tree.

If you provide it with no argument, it will show all the processes from init or systemd.

However, if you give it a process id, it will show all that processes as the root of the tree. In other words, it will show all the processes initiated by that process.

You can use the same $$ bash parameter we saw in method 1.

pstree $$

Method 4

The last method is using the files in proc directory. If you read the article about checking CPU info in Linux, you probably already know that this directory contains the runtime system information about your Linux system.

You can use the following command to get the shell you are using:

cat /proc/$$/cmdline

The output should give you the name of the shell.

Bonus Tip: Know the version of the shell

So you learned how to know which shell you are using. What about the version of the shell you are using? You can get the version of the shell simply by adding –version after the name of your running shell.

For example, if you are running zsh, you can use this:

zsh --version

The output will give you the version information:

zsh 5.4.2 (x86_64-ubuntu-linux-gnu)

I hope this quick tutorial helped you in finding out which shell you are running. Don’t forget to check out another simple tip on changing shell in Linux.

By the way, do you use some other way to check which shell you are using? Why not share it with us in the comment section?