Friday, March 11, 2011

Which Shell you are right now?

It's a pretty simple question. But even people good at shell scripting can't answer correctly most of the time. The reason is people tend to use the value of the environment variable (SHELL) as current shell. But it is not correct, if you are not inside the login shell.

Note 1: echo $SHELL -> gives always login shell value
Note 2: echo $0 -> gives always the current shell
Note 3: cat /etc/shells -> lists valid login shells. It doesn't mean that all shells are available in your system.

Examples:
volcano@volcano-laptop:~/shellscript$ echo $SHELL
/bin/bash
volcano@volcano-laptop:~/shellscript$ echo $0
bash
volcano@volcano-laptop:~/shellscript$ ksh
$ echo $SHELL
/bin/bash
$ echo  $0
ksh
$ exit
volcano@volcano-laptop:~/shellscript$ echo $0
bash
volcano@volcano-laptop:~/shellscript$

volcano@volcano-laptop:~/shellscript$ cat /etc/shells
# /etc/shells: valid login shells
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/tcsh
/bin/tcsh
/usr/bin/esh
/bin/dash
/bin/bash
/bin/rbash
/usr/bin/screen
/bin/ksh93
volcano@volcano-laptop:~/shellscript$ tcsh
The program 'tcsh' is currently not installed.  You can install it by typing:
sudo apt-get install tcsh

No comments:

Post a Comment