Categories
Unix & Linux

How to determine current terminal shell in macOS/FreeBSD

Is there an easy way to determine what shell I’m using in terminal?

I’ve found several ways, from most to least reliable. The following works in the four shells I have installed on my system (bash, zsh, csh, tcsh):

First method

$ ps -p $$
  PID  TT  STAT      TIME COMMAND
14143   0  Ss     0:00,03 -bash (bash)

Second method

$ echo $0
-bash

Third method

Check $SHELL; this is a last resort, as it specifies your default shell and not necessarily the current shell.

$ echo $0
csh

$ echo $SHELL;
/usr/local/bin/bash

Leave a Reply

Your email address will not be published. Required fields are marked *