Subject: Re: A shell gotcha
To: John F. Woods <jfw@jfwhome.funhouse.com>
From: Simon J. Gerraty <sjg@frodo.dn.itg.telecom.com.au>
List: current-users
Date: 04/18/1995 14:05:03
> Last night, I installed the latest copy of pdksh (my favorite shell),
Mine too :-)
> and all hell broke loose; my login script was causing complaints about
> "let: arith: bad syntax (top=0)" and many other fiendish complaints,
> including a gripe about /usr/bin/cpp not working! After much hair
> tearing and searching for latest-and-greatests of several alternative
> shells, I finally discovered that /bin/sh "now" recognizes the ENV
> environment variable, and it was choking trying to understand my
I'm told that $ENV is needed for POSIX. Of course the POSIX shell is
supposed to be almost (but not quite) ksh. There are lots of ksh'isms
that /bin/sh does not (yet) handle and while I protect all ksh
specifics in /etc/profile,.profile and even $ENV, with:
if [ "$RANDOM" != "$RANDOM" ]; then
# its ksh
else
# its not-ksh
fi
This does not help if you try to use something like:
HOSTNAME=`hostname`
HOST=${HOSTNAME%%.*}
in one of these scripts as (/bin/sh in 1.0 anyway) syntax checks the
lines even though it is not going to execute them.
BTW, the above test using $RANDOM works for all ksh variants. I only
use $KSH_VERSION to differentiate between pd-ksh and the real thing as
changing key bindings is different.
Check out the /etc/profile and /etc/ksh.kshrc that are in the package
kshenv.tgz on sun-lamp.
Anyway the bottom line is that you cannot have any ksh specific
syntax in ksh's startup file ($ENV). This situation is ridiculous but
blame POSIX...
--sjg