Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between $0 and $SHELL

Tags:

shell

I would like to know the exact difference between $0 and $SHELL. I know that these two are used to know the shell info. It would be great if some one explain with examples.

What does it indicate if both show different values as below ?

# echo $0
ksh
# echo $SHELL
/sbin/sh
#
like image 428
Vinod Yadav Avatar asked Feb 22 '23 01:02

Vinod Yadav


1 Answers

SHELL is just an environment variable, while $0 is the path of the currently running program. The user should set SHELL to the value of the preferred shell, similar to the way the user sets PAGER and EDITOR. Any program that needs to spawn a shell should check the value of SHELL to determine which shell to invoke. SHELL is not the path of the shell you get when you login. It will not change when a new shell is run any more than PAGER will change if it is set to less but the user invokes more, or if EDITOR is set to vi and the user runs emacs. For instance:

$ echo $0 $SHELL
bash /bin/bash
$ exec csh
% echo $0 $SHELL
csh /bin/bash
like image 84
William Pursell Avatar answered May 07 '23 04:05

William Pursell