3 Methods to Check Which Shell Currently Using in Linux

3 Methods to Check Which Shell Currently Using in Linux

Shell is a command line interpreter. There are various shells in Linux. The bash shell is integrated in many Linux distributions. There also are ksh, zsh, tcsh. This tutorial provides 3 methods to check which shell currently using in Linux.

Method 1 - $0 special parameter

The $0 is a special parameter that contains the name of the currently used shell. Use echo command to print value:

echo $0

Output example:

bash

Method 2 - ps command

The ps command allows to get a snapshot of the current processes. The -p option allows to select the process by ID (PID). The $$ is a special parameter that contains the process ID of the currently used shell.

ps -p $$

Output example:

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

Method 3 - /etc/passwd file

The /etc/passwd is a text file which contains details about users such as username, user ID, group ID, shell, etc. Each line in a file contains 7 fields. The last field is shell.

grep "^$USER" /etc/passwd | cut -d: -f7

Output example:

/bin/bash

Leave a Comment

Cancel reply

Your email address will not be published.