bin/93644: Wrong handling of 'return 1' in /bin/sh with 'set -e'

Martin Beran mb at tns.cz
Tue Feb 21 06:10:09 PST 2006


>Number:         93644
>Category:       bin
>Synopsis:       Wrong handling of 'return 1' in /bin/sh with 'set -e'
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 21 14:10:05 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Martin Beran
>Release:        6.0-RELEASE-p4
>Organization:
Trusted Network Solutions, a.s.
>Environment:
FreeBSD mb.tns.cz 6.0-RELEASE-p4 FreeBSD 6.0-RELEASE-p4 #4: Fri Feb  3 12:09:35 CET 2006     root at mb.tns.cz:/usr/obj/usr/src/sys/MB  i386
>Description:
Shell /bin/sh terminates a script when a function returns with a nonzero return value and 'set -e' is in effect, even when the return value of the function is tested, e.g., by 'if'. This bug occurs only if return is not the last command in the function.
>How-To-Repeat:
#!/bin/sh -e
f() {
    return 1
    :
}
if f; then :; fi
echo END

I think this script should print "END", but is does not. It works as expected after changing function f to
f() {
    return 1
}
or
f() {
    return 1 || :
    :
}
>Fix:
              
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list