Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Feb 2006 14:08:00 GMT
From:      Martin Beran <mb@tns.cz>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/93644: Wrong handling of 'return 1' in /bin/sh with 'set -e'
Message-ID:  <200602211408.k1LE80rW024360@www.freebsd.org>
Resent-Message-ID: <200602211410.k1LEA5P6085835@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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@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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200602211408.k1LE80rW024360>