Subject: Which shell am I in?
To: None <netbsd-help@netbsd.org>
From: Ian Goldby <Ian.Goldby@mail.com>
List: netbsd-help
Date: 03/24/2001 14:51:52
There must be an easy answer to this one. How can a shell script (such
as .profile or .kshrc) find out which shell it is in? I tried using the
environment variable SHELL, but it often reports the parent process
shell rather than the actual shell.

E.g. If I start in ksh and echo $SHELL I get /bin/ksh. If I then start
a sh from  within ksh and echo $SHELL, it's still /bin/ksh.

I need to be able to distinguish, because .kshrc (my ENV file) has some
ksh-specific stuff in it, and it causes errors when commands start
their own sub-shells using sh. So I want .kshrc to have a line at the
top that will exit if it's not being run from ksh.

(I've made a temporary solution by renaming /bin/sh as /bin/sh.old and
making a symbolic link from sh to ksh, so that whenever sh is started,
ksh comes up instead. That's what happens under IRIX. But I'm not sure
if it is an optimal solution.)

Thanks

Ian