83

Is there an easy way by which I can tell which type of Unix shell I am in?

A command that shows whether I am in a Bash, C shell, KornShell (ksh), tcsh, or Z shell (zsh)?

E.g.,

whatshellisthis

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RHT
  • 4,974
  • 3
  • 26
  • 32

5 Answers5

135

Try:

echo $0

This often works across a range of shells.

ggg
  • 1,366
  • 1
  • 8
  • 2
21

Mac

ps

  PID TTY           TIME CMD
  223 ttys000    0:00.33 -bash

OpenBSD

ps

  PID TT  STAT       TIME COMMAND
20038 p0  Ss      0:00.01 -ksh (ksh)
22251 p0  R+      0:00.00 ps

Or just echo $SHELL.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
  • 10
    I think `$SHELL` is the default shell for the system (or user), which is usually (but not necessarily) the shell that is actually being used at any given moment. – David Z Jul 28 '10 at 02:22
12

The echo $SHELL command will give you your shell name relative to root.

Javier
  • 12,100
  • 5
  • 46
  • 57
a.saurabh
  • 1,163
  • 10
  • 15
  • 1
    SHELL is not guaranteed to be set. For instance, my login shell is bash, but is I run /bin/sh at the command line, SHELL is still /bin/bash even though /bin/sh ls dash. – Mark Evans May 12 '14 at 03:12
  • 2
    $SHELL is the login shell. If your login shell is bash and you start tcsh, then $SHELL will still be bash even tough the shell you are running is tcsh. – Ole Tange Jul 18 '14 at 13:23
  • check out # ps -p $$ | tail -1 | awk '{print $4}' – Ranjithkumar T Oct 15 '14 at 05:27
8

Every shell I know of sets the $ variable ($$) to its pid. So...

ps | grep $$
pra
  • 8,479
  • 2
  • 18
  • 15
  • Fish is the exception. You need to use %self – rominf Sep 12 '14 at 18:51
  • Sometimes I feel like fish should not be counted among "unix shells". We're very comfortable in our pile of spaghetti, please don't straighten all the noodles. – pra Sep 03 '21 at 03:19
6

If you are using the OS X terminal, then the shell is specified in the Terminal's title bar when you launch it - like so: Terminal - ShellName - 80x24

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alex
  • 9,250
  • 11
  • 70
  • 81