Subject: Re: Which shell am I in?
To: Ian Goldby <Ian.Goldby@mail.com>
From: Matthias Buelow <mkb@mukappabeta.de>
List: netbsd-help
Date: 03/25/2001 01:38:27
Ian Goldby <Ian.Goldby@mail.com> writes:

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

test -z "$RANDOM" (only set in ksh and bash, which you can check against
with BASH_VERSION).  pdksh (as used in NetBSD) also sets KSH_VERSION,
which I don't recommend to use since the real ksh doesn't set it (ksh93
sets the .sh.version variable which you can check with ${.sh.version} but
ksh88 and pdksh won't understand this and give an error.)  Testing RANDOM
works reliably, though.  I'd also recommend to guard things your .kshrc 
against non-interactive shells (if you have parts in it that only make
sense in interactive shells) by checking for the "i" parameter with
"case $- in *i*) ...;; esac" (works with all Bourne compatible shells).

mkb