Date: Wed, 12 Jun 2002 17:41:11 -0400 From: parv <parv@pair.com> To: Joe Kelsey <joek@mail.flyingcroc.net> Cc: freebsd-bugs@FreeBSD.org Subject: Re: bin/39198: sh aborts on variables with periods Message-ID: <20020612214110.GA30199@moo.holy.cow> In-Reply-To: <200206122010.g5CKA3L09165@freefall.freebsd.org> References: <200206122010.g5CKA3L09165@freefall.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
in message <200206122010.g5CKA3L09165@freefall.freebsd.org>,
wrote Joe Kelsey thusly...
>
> The following reply was made to PR bin/39198; it has been noted by GNATS.
>
> From: Joe Kelsey <joek@mail.flyingcroc.net>
>
> Matthias Buelow wrote:
>
> > Joe Kelsey wrote:
> >
> >> /bin/sh does not gracefully accept variables with periods.
> >
> >
> > Neither does ksh88, the direct predecessor to ksh93...
> >
> >> Either /bin/sh has to allow parameters to contain periods or
> >> it has to provide a reliable method of detecting /bin/sh
> >> versus ksh.
> >
> > Try to check for RANDOM, which does not exist on sh. ...
> > Similarly probably for zsh. Then try to check for KSH_VERSION
> > to draw the line between ksh and pdksh.
> >
> ... I just want to separate generic ksh from /bin/sh, and RANDOM
> should do that. The check for KSH_VERSION fails in ksh93 since
> they went to the .sh.version parameter and dropped KSH_VERSION
> completely, a real killer.
i was in a similar situation which resulted in a thread on
comp.unix.shell titled "of ~/.profile, bourne shell, and ksh93's
${.sh.version}". in addition to that, i also got a private reply...
---- quote ----
A test like the following can be used to recognize non-ksh/non-bash
shells. I.e. bourne/csh
if test $RANDOM = $RANDOM
then
bsh/csh
else
ksh/bash
fi
For determining ksh88 vs ksh93, and which version of ksh93, I define 2
functions which are in an FPATH directory.
#### isksh93 ####
function isksh93 {
{ : ${.sh.version} ; } >/dev/null 2>&1
return $?
}
#### kshversion ####
function kshversion
{
exec 7>&2 2>/dev/null
typeset ver rtrn
ver=`echo ${.sh.version}`
rtrn=$?
echo "${ver}" | sed -e 's/Version M[-/0-9 ]*//' -e 's/[ $
]*$//'
exec 2>&7 7>&-
return $rtrn
}
# Most ksh's output a version string (invoked with <Esc><Ctrl> V)
# of the form:
# Version M 1993-12-28 k+
# Version M-12/28/93d
# Version M-11/16/88i
# ksh93's also have the same string in a special variable .sh.version
# that ksh88 considers an invalid variable name.
#
# kshversion gives two types of information, return status and stdout
#
# shell type return status stdout
# ---------- ------------- ------
# ksh88 1 probably nothing
# ksh93 0 the version letter ...
#
# Note, this is done with emperical tests, no certainty what will
# happen with untested ksh versions
---- unquote ----
hth.
- parv
--
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020612214110.GA30199>
