How to Check Which Shell Is Being Used in Terminal?

You can check which shell you're using in terminal using the ps command which will show you a list of currently running processes. To filter out the clutter and only show the shell name, you could use the ps command with the following options:

ps -h -o comm -p $$

Where the flags are used for the following purposes:

  • -h: to remove headers;
  • -o comm: to print only the executable name(s). You may also use -o comm="" to get rid of the "COMM" header;
  • -p $$: to narrow it down to the process id returned by "$$" (which refers to the process id of the shell in which the command is run).

If that does not work for you, you may try using echo $0, which (when run inside a POSIX compliant shell) would return the name of the shell.

Please note that the methods mentioned in this article are meant as a productivity tip to allow you to quickly check which shell you're using in your terminal. Please do not use these in your scripts for the purpose of getting the shell name as they may mean something else in that context.


This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.