🐚 How to check which shell you are using on Linux

Linux provides a wide variety of shells by default.

There is a bash (Bourne Again shell) shell that comes by default on many systems.

We also have sh (Bourne shell), tcsh (TC shell), csh (C shell), Zsh (Z shell), and ksh (Korn shell).

Want to know which shell you are using on your Linux system?

In this tutorial, we’ll explore the different ways you can use to check which shell you are using on your Linux machine.

1) Using echo commands

The Linux echo command is a built-in command that is used to output the string passed as an argument.

Alternatively, you can use the echo command to test the shell in which you are running commands.

To do this, run:

$ echo $SHELL
/bin/bash

The output shows that I am using the bash shell. Alternatively, you can simply run the command:

$ echo $0
bash

To get the PID of the shell you are currently in, run:

$ echo $$

2) Using the ps command

The ps command in its basic format, commonly used to list running processes, also sheds light on the shell you are using.

Just run the command:

$ ps
PID    TTY   TIME      CMD 
5684   pts/0 00:00:00  bash

From the first line of output we can clearly see the PID of the shell, and the last column outputs the type of the shell, in this case bash.

Alternatively, you can run the command:

$ ps -p $$

3) Check the shell by looking at the file / etc / passwd

You can use the gre command to check the / etc / passwd file, which contains user attributes such as username, user ID, and group ID.

To display the shell in use, call the command:

$ grep "^$USER" /etc/passwd

In the very last segment, we will see the bash being used, in this case / bin / bash.

It also gives you an idea of ​​which shell opens first when you first log in.

3) Let’s check the shell using the lsof command

Usually the lsof command, short for list of open files, is used to provide a list of open files on your system.

However, when used with the -p $$ flag, it gives a pointer to the shell you are in when you look at the first column of the output.

For example, we will clearly see that we are in a bash shell.

$ lsof -p $$

How to check available skins

We’ve covered the different ways you can use to test the shell you’re currently in.

If you want to know what shells are allowed on your system, check the / etc / shells file.

This file will give you full paths to valid shells.

Using the cat command, view the file as follows:

$ cat /etc/shells

Conclusion

In this tutorial, we’ve shared some simple yet nifty ways you can use to find out which shell you’re running under.

This is important when writing scripts so you can know how to write the shebang header.

We really hope this guide was helpful.

Send us a message and don’t forget to share this guide on social media.

Sidebar