22
Dec

Determine Which Terminal Shell You’re Running

It’s very simply to determine which shell you’re using while logged into a Linux terminal.  Simply run the following command:

ps -p $$ | tail -n1 | cut -d" " -f26

You’ll get in return, the shell command you’re using (plus the full path to it).

[email protected]$ ps -p $$ | tail -n1 | cut -d" " -f26
/usr/bin/bash

Another way to do it would be to use awk instead of cut:

ps -p $$ | tail -n1 | awk '{print $NF}'

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:


There's 2 Comments So Far

  • [email protected]
    December 23rd, 2010 at 12:00 pm

    Just got an email from a subscriber with good suggestions for other ways of determining which shell you’re running:

    Hi Derek,

    Another way to get this is

    cat /proc/$$/cmdline

    Though they may or may not be an ‘-‘ before or after the shell name,
    depending on whether or not you are in a login shell.

    And another way of getting the current process command just using ps, is

    ps -p $$ -o comm=

    As ever there is always lots of ways of doings things 🙂

    cheers
    Jim

  • Kyle
    January 11th, 2011 at 6:20 pm

    Or just check the environment variable $SHELL

    > echo ‘$SHELL’
    /bin/bash

Share your thoughts, leave a comment!