NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/49595: unset built-in exits with failure if parameter not set



>Number:         49595
>Category:       bin
>Synopsis:       unset built-in exits with failure if parameter not set
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 22 04:10:00 +0000 2015
>Originator:     William Ahern
>Release:        6.1.1
>Organization:
>Environment:
NetBSD  6.1.1 NetBSD 6.1.1 (GENERIC) amd6
>Description:
POSIX description of the unset built-in utility says:

"
Unsetting a variable or function that was not previously set shall not be considered an error and does not cause the shell to abort.
"

and

"
EXIT STATUS
0 All name operands were successfully unset.
>0 At least one name could not be unset.
"

While trying to unset a non-existent variable doesn't normally cause the shell to exit (compare PR 47795), the command still exits with a status of 1. So, the shell will exit if strict errors are enabled using set -e or set -o errexit.

NetBSD's /bin/sh is the only shell with this behavior I've found. I've tested /bin/sh on AIX 7, Solaris  11.1, OpenBSD 5.5, OS X 10.2 (BETA), FreeBSD 9.0, and Ubuntu 14.04.

I suppose one could interpret NetBSD's behavior as conforming. But I find it leads to unnecessarily complex code like `unset FOO || true` or `[ "${FOO-unset}" = "unset" ] || unset FOO`

>How-To-Repeat:
Following script should print "OK".

#!/bin/sh
FOO=bar
unset FOO
set -e
unset FOO
printf "OK\n"

>Fix:
Remove the following from c_unset in ksh/c_sh.c:

if (!(vp->flag & ISSET))
        ret = 1;




Home | Main Index | Thread Index | Old Index