Testing for >= ksh93

Testing for >= ksh93

am 07.09.2007 07:26:20 von whystopnow

Is there a way to test in a script if the version of ksh is >= ksh93?

I thought about examining ${.sh.version}, which is set to something
like "Version M 1993-12-28 s+". I could grep for 1993, but of course
someday when ksh200x comes out, that will fail.

I suppose I could parse out the year and test it as an integer to be
>= 1993. But I'm not sure that the version string is guaranteed to be
in that format.

I could I suppose try to use some ksh93-specific feature in an eval
and see if it works.

Any other ideas?

Thanks.

Re: Testing for >= ksh93

am 07.09.2007 11:01:43 von Janis Papanagnou

whystopnow wrote:
> Is there a way to test in a script if the version of ksh is >= ksh93?
>
> I thought about examining ${.sh.version}, which is set to something
> like "Version M 1993-12-28 s+". I could grep for 1993, but of course
> someday when ksh200x comes out, that will fail.

(I not yet see any ksh200x; they're still talking about fixing and
working on ksh93.)

> I suppose I could parse out the year and test it as an integer to be
>
> >= 1993. But I'm not sure that the version string is guaranteed to be
>
> in that format.

I would indeed go that way. And since they are using an ISO standard
date schema you can be quite sure that there will be a YYYY-MM-DD
string in that variable.

> I could I suppose try to use some ksh93-specific feature in an eval
> and see if it works.

${.sh.version} is a ksh93-specific feature.

> Any other ideas?

In the first place I wouldn't check for 200x versions, because any
feature that is not yet deprecated would very likely be supported
by a ksh200x.

If you like to heavily restrict yourself you can also completely
avoid any features that are not defined in POSIX; that way you'll
gain a better portability (in any non-ancient Unix environments).

Janis

> Thanks.
>

Re: Testing for >= ksh93

am 07.09.2007 13:04:48 von wendlin1974

whystopnow wrote:
> Is there a way to test in a script if the version of ksh is >= ksh93?
>
> I thought about examining ${.sh.version}, which is set to something
> like "Version M 1993-12-28 s+". I could grep for 1993, but of course
> someday when ksh200x comes out, that will fail.
>
> I suppose I could parse out the year and test it as an integer to be
> >= 1993. But I'm not sure that the version string is guaranteed to be
> in that format.
>
> I could I suppose try to use some ksh93-specific feature in an eval
> and see if it works.
>
> Any other ideas?

Try to ask in the ksh93-integration-discuss@opensolaris.org forum,
David Korn himself answers questions there.

>
> Thanks.

--
Wendy

Re: Testing for >= ksh93

am 07.09.2007 18:41:24 von RichK

According to whystopnow :
:Is there a way to test in a script if the version of ksh is >= ksh93?
:
:I thought about examining ${.sh.version}, which is set to something
:like "Version M 1993-12-28 s+". I could grep for 1993, but of course
:someday when ksh200x comes out, that will fail.
:
:I suppose I could parse out the year and test it as an integer to be
:>= 1993. But I'm not sure that the version string is guaranteed to be
:in that format.
:
:I could I suppose try to use some ksh93-specific feature in an eval
:and see if it works.
:
:Any other ideas?
:
:Thanks.
:

How about just check if .sh_version option. is valid; since ksh93 .sh_*
and not ksh88.

richk

Re: Testing for >= ksh93

am 07.09.2007 22:00:45 von spcecdt

In article <1189142780.615531.244820@w3g2000hsg.googlegroups.com>,
whystopnow wrote:
>Is there a way to test in a script if the version of ksh is >= ksh93?
>
>I thought about examining ${.sh.version}, which is set to something
>like "Version M 1993-12-28 s+". I could grep for 1993, but of course
>someday when ksh200x comes out, that will fail.
>
>I suppose I could parse out the year and test it as an integer to be
>>= 1993. But I'm not sure that the version string is guaranteed to be
>in that format.
>
>I could I suppose try to use some ksh93-specific feature in an eval
>and see if it works.

Instead of testing for ksh93 in general, I usually test for the specific
features I actually *need*.

John
--
John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/

Re: Testing for >= ksh93

am 08.09.2007 11:58:31 von Geoff Clare

wendlin1974 wrote:

> whystopnow wrote:
>> Is there a way to test in a script if the version of ksh is >= ksh93?

> Try to ask in the ksh93-integration-discuss@opensolaris.org forum,
> David Korn himself answers questions there.

That forum is not for general questions about ksh93. It is a place to
discuss issues related to the integration of ksh93 into OpenSolaris.

--
Geoff Clare

Re: Testing for >= ksh93

am 11.09.2007 05:33:00 von brian_hiles

Geoff Clare wrote:
> wendlin1974 wrote:
> > whystopnow wrote:
> > > ...
> That forum is not for general questions about ksh93. It is a place to
> discuss issues related to the integration of ksh93 into OpenSolaris.

The "appropriate" forum is https://mailman.research.att.com/pipermail/ast-users/;
however, don't post there with a newby question or you
WILL get flamed. C.U.S. is better. And we're nicer, too :)

For a survey of past programmatic solutions, see:

http://groups.google.com/group/comp.unix.shell/browse_thread /thread/7daab0f241b22446/a0bc8f9e5d362bf2?lnk=st&q=&rnum=2#a 0bc8f9e5d362bf2

And, for completeness, a survey of various probes scripts,
including the above:

http://groups.google.com/group/comp.unix.shell/browse_thread /thread/3c5c5081affa2f0a/2ea0bcd47c5f2d6c?lnk=st&q=&rnum=1#2 ea0bcd47c5f2d6c

You should be aware that I have stopped developing whichshell,
in large part because of a recent interchange between Zdenek
Sekera and I. The canonical shells are both changing too fast,
and whose feature sets are converging to standards compliance,
making version discrimination problematic. Another modality
must now be pursued rather than detection of documented syntax
and exploitation of shell idioms.

The aforementioned advice given is probably sufficient. Try:

shver=` print -- ${.sh.version//!([0-9-])/} ` 2>/dev/null # not tested

It's too bad my function toolkit for version compliance is
not yet ready for distribution. It both emulates modern shell
functionality for older shells (like autoloading) as well as
providing a transparent abstraction layer to redirect autoloading
to the appropriate function version (that is, one for each shell),
plus a downward compatible function library for the "lowest
common denominator" of expected functionality written in
acceptably efficient code. Now _that_ would have been the
real solution....

=Brian

Re: Testing for >= ksh93

am 26.09.2007 01:42:58 von Roland Mainz

Geoff Clare wrote:
> wendlin1974 wrote:
> > whystopnow wrote:
> >> Is there a way to test in a script if the version of ksh is >= ksh93?
>
> > Try to ask in the ksh93-integration-discuss@opensolaris.org forum,
> > David Korn himself answers questions there.
>
> That forum is not for general questions about ksh93. It is a place to
> discuss issues related to the integration of ksh93 into OpenSolaris.

Erm... IMO there is no problem with asking general-purpose questions in
that list[1] (however the more or less "official" ksh93 list is the
"ast-users" list (see
https://mailman.research.att.com/pipermail/ast-users/)) ...

[1]=(...and before someone starts to complain: I'm the list admin of the
ksh93-integration@opensolaris.org list...)

----

Bye,
Roland

--
__ . . __
(o.\ \/ /.o) roland.mainz@nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O;)

Re: Testing for >= ksh93

am 26.09.2007 03:04:18 von Roland Mainz

whystopnow wrote:
> Is there a way to test in a script if the version of ksh is >= ksh93?
>
> I thought about examining ${.sh.version}, which is set to something
> like "Version M 1993-12-28 s+". I could grep for 1993, but of course
> someday when ksh200x comes out, that will fail.

Erm, the current version is "ksh93s+" which means "korn shell based on
spec from 1993, version s+" (the "M" after the "Version" indicates that
the shell is compiled with multibyte support, e.g. it can handle
non-ASCII charatcers from languages like japanese/chinese/etc. if the
locale support this).

The "1993-12-28" can therefore be ignored for now since it's the same
since the initial ksh93 release and won't change in the forseeable
future, leaving the "s+" as the real version indicator.

[snip]
> Any other ideas?

On Solaris the following test works:
-- snip --
$ sh -c ' [ "`(echo ${.sh.version}) 2>/dev/null`" != "" ] && echo
"isksh93"'
$ ksh -c ' [ "`(echo ${.sh.version}) 2>/dev/null`" != "" ] && echo
"isksh93"'
$ ksh93 -c ' [ "`(echo ${.sh.version}) 2>/dev/null`" != "" ] && echo
"isksh93"'
isksh93
-- snip --
This works with the original Bourne shell, ksh88, ksh93 and bash...

----

Bye,
Roland

--
__ . . __
(o.\ \/ /.o) roland.mainz@nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 7950090
(;O/ \/ \O;)