Sunday, March 18, 2012

echo $SHELL and echo $0

"How do you identify your current shell?" is one of the frequently asked interview question.


Some would say "echo $SHELL" and some would say "echo $0". So, which is the right answer?


See for yourself!
root > grep ^root /etc/passwd
root:x:0:0:root:/root:/bin/bash

root > bash
root > echo $SHELL
/bin/bash
root > echo $0
-bash

root > ksh
root > echo $SHELL
/bin/bash
root > echo $0
ksh
Got it?


$SHELL will always print the login shell. $0 will print the current shell.


Good Day!

3 comments:

  1. waht is commAND to find the login shell?

    ReplyDelete
    Replies
    1. To know the login shell, use echo $SHELL
      To know the current shell, use echo $0

      Delete