A bug has been filed against /usr/xpg4/bin/sh (and /bin/ksh) as well,
for the same issue:
6791841 */usr/xpg4/bin/sh* unset of a variable which is not set should return 0
April
> Date: Fri, 09 Jan 2009 23:36:26 +0100
> From: Roland Mainz <roland.mainz at nrubsig.org>
> X-Accept-Language: en
> To: April Chin <April.Chin at eng.sun.com>, OpenSolaris Shell discussions
<shell-discuss at opensolaris.org>, ksh93-integration-discuss
<ksh93-integration-discuss at opensolaris.org>, David Korn <dgk at
research.att.com>
> Subject: Re: CR 6791838 Created P3 shell/korn93 *ksh93* unset of a
variablewhich is not set should return 0
> X-Virus-Scanned: ClamAV 0.94.1/8848/Fri Jan 9 14:16:38 2009 on
mail-in-11.arcor-online.net
> X-Virus-Status: Clean
>
> bugmail-sender at Sun.COM wrote:
> >
> > *Synopsis*: *ksh93* unset of a variable which is not set should return 0
> >
> >
> > *Change Request ID*: 6791838
> >
> > *Synopsis*: *ksh93* unset of a variable which is not set should return 0
> >
> > Product: solaris
> > Category: shell
> > Subcategory: korn93
> > Type: Defect
> > Subtype: Functionality
> > Status: 5-Cause Known
> > Substatus:
> > Priority: 3-Medium
> > Introduced In Release:
> > Introduced In Build:
> > Responsible Engineer: <User 1-5Q-5151>
> > Keywords:
> >
> > === *Description*
============================================================
> > In ksh93, the special builtin "unset" will exit 1 when its argument is a
> > variable which is not set, but it should exit 0, according to the POSIX
standards.
>
> Erm... I interpret the standard a bit different in this case:
> http://www.opengroup.org/onlinepubs/000095399/utilities/unset.html says:
> -- snip --
> EXIT STATUS
>
> 0
> All name operands were successfully unset.
> >0
> At least one name could not be unset.
> -- snip --
>
> Both ksh88, ksh93 and /usr/xpg4/bin/sh in Solaris behave like this:
> -- snip --
> $ /usr/xpg4/bin/sh -c 'unset kjashdjkashd || print "unset returned
> non-zero exit code"'
> unset returned non-zero exit code
> $ ksh -c 'unset kjashdjkashd || print "unset returned non-zero exit
> code"'
> unset returned non-zero exit code
> $ ksh93 -c 'unset kjashdjkashd || print "unset returned non-zero exit
> code"'
> unset returned non-zero exit code
> -- snip --
>
> Don: Is there any clarification request which defined the behaviour of
> "unset" more precisely ?
>
> ----
>
> Bye,
> Roland
>
> --
> __ . . __
> (o.\ \/ /.o) roland.mainz at nrubsig.org
> \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
> /O /==\ O\ TEL +49 641 3992797
> (;O/ \/ \O;)