Linux – How to Tell Which Shell

By | 2020-09-23

The easiest way to tell which shell you are using is by looking at what the exe link points to in your shell process’s /proc directory. You can use the command ls -l /proc/$$/exe. Below is an example:

$ ls -l /proc/$$/exe
lrwxrwxrwx 1 tyler tyler 0 Sep 22 19:39 /proc/19867/exe -> /bin/bash

The special shell variable $$ is the process ID of your shell's process. The symbolic link exe within a processes directory in /proc points to the path of the respective process's executable file. The -l option of ls shows you detailed information about files, including the location symbolic links point to.

Here are some examples of trying this with different shells.

$ ls -l /proc/$$/exe
lrwxrwxrwx 1 tyler tyler 0 Sep 22 19:39 /proc/19867/exe -> /bin/bash
$ ksh
$ ls -l /proc/$$/exe
lrwxrwxrwx 1 tyler tyler 0 Sep 23 19:13 /proc/2719/exe -> /bin/ksh93
$ csh
% ls -l /proc/$$/exe
lrwxrwxrwx 1 tyler tyler 0 Sep 23 19:13 /proc/2728/exe -> /bin/bsd-csh
% sh
$ ls -l /proc/$$/exe
lrwxrwxrwx 1 tyler tyler 0 Sep 23 19:13 /proc/2730/exe -> /bin/dash/

There are other methods. You could always look at the contents of $0. nixCraft covers this method pretty thoroughly. This has a few drawbacks though. It doesn't work with all shells, such as some versions of csh:

$ csh
% ls -l /proc/$$/exe
lrwxrwxrwx 1 tyler tyler 0 Sep 23 19:28 /proc/3075/exe -> /bin/bsd-csh
% echo $0
No file for $0.
$ echo $0
ksh

Another problem with the $0 method is symbolic links. For example, sh is often symbolically linked to a shell that is compatible. In the example earlier, it was linked to /bin/dash