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 thoughts on “Short Tip: determine current shell

  1. 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. $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.

  3. $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.