Short Tip: determine current shell

shell.png
To figure out the current shell you’re using, like bash, zsh or sh, just call ps -p $$:

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

Pretty helpful if you’re playing with different shells at the same time.

About these ads

4 Responses to “Short Tip: determine current shell”

  1. jensp Says:

    The variable $SHELL contains the path to the current shell and $0 only represents the first argument given to a program (aka the name of the actual programm). To understand what I mean do the following:
    cd /home/liquidat
    ../../tmp/../bin/bash
    echo $0

  2. liquidat Says:

    Ah, thanks, didn’t knew that, I never stop learning ;)

  3. fess Says:

    $SHELL is just an enironment variable, it’s not always correct

    fess@McBean-1005% echo $SHELL
    /bin/zsh
    fess@McBean-1006% /bin/bash
    McBean:~ fess$ echo $SHELL
    /bin/zsh

    so where you think it would be bash it’s still zsh.

  4. Aerodonkey Says:

    $SHELL is the default shell. My question is how to determine the type of the shell in the script if the script is executable and invoked directly by the console (e.g., ./shell.sh).


Comments are closed.

Follow

Get every new post delivered to your Inbox.

Join 84 other followers

%d bloggers like this: