bin/111343: sh and bash with -e sometimes fail to test errors in functions

Alexander Melkov melkov at comptek.ru
Sat Apr 7 03:20:03 UTC 2007


>Number:         111343
>Category:       bin
>Synopsis:       sh and bash with -e sometimes fail to test errors in functions
>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:   Sat Apr 07 03:20:02 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Alexander Melkov
>Release:        6.2
>Organization:
>Environment:
FreeBSD melkov.ru 6.2-PRERELEASE FreeBSD 6.2-PRERELEASE #9: Thu Jan 11 23:13:53 MSK 2007     ---- at melkov.ru:/usr/obj/usr/src/sys/MELKOV  i386
>Description:
When shell function is called as a part of complex command with || operator, effect of -e (i.e. exit after first untested command returns error status) within that function is disabled.

>How-To-Repeat:
1. Create script
==> test.sh <==
set -e

qq ( ) {
  false
  echo ok
}

qq || echo failed
<end script>

2a) FreeBSD 4.11
Command:
 sh -e test.sh
<no output>

Command:
 bash -e test.sh
Output:
 ok

2b) FreeBSD 6.2
Command:
 sh -e test.sh
Output:
 ok

Command:
 bash -e test.sh
Output:
 ok

In all cases, expected output is:
 failed

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list