From syspmc@dtir.qld.gov.au  Mon May 12 21:12:59 1997
Received: from bunyip.cc.uq.edu.au (daemon@bunyip.cc.uq.edu.au [130.102.2.1])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id VAA27694
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 12 May 1997 21:12:52 -0700 (PDT)
Received: (from daemon@localhost)
	by bunyip.cc.uq.edu.au (8.8.5/8.8.5) id OAA03776
	for FreeBSD-gnats-submit@freebsd.org; Tue, 13 May 1997 14:12:07 +1000
Received: from goblin.devetir.qld.gov.au by ogre.dtir.qld.gov.au (8.7.5/DEVETIR-E0.3a) with ESMTP
	id OAA26967 for <FreeBSD-gnats-submit@freebsd.org>; Tue, 13 May 1997 14:12:17 +1000 (EST)
Received: (from syspmc@localhost) by goblin.devetir.qld.gov.au (8.8.5/8.7.3) id OAA14680; Tue, 13 May 1997 14:11:59 +1000 (EST)
Message-Id: <199705130411.OAA14680@goblin.devetir.qld.gov.au>
Date: Tue, 13 May 1997 14:11:59 +1000 (EST)
From: Phil Chadwick <syspmc@dtir.qld.gov.au>
Reply-To: syspmc@dtir.qld.gov.au
To: FreeBSD-gnats-submit@freebsd.org
Subject: Bug report for FreeBSD 2.2.x /bin/sh
X-Send-Pr-Version: 3.2

>Number:         3587
>Category:       bin
>Synopsis:       FreeBSD 2.2.x /bin/sh functions return wrong exit status
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 12 21:20:01 PDT 1997
>Closed-Date:    Tue May 13 09:33:18 PDT 1997
>Last-Modified:  Tue May 13 09:34:42 PDT 1997
>Originator:     Phil Chadwick
>Release:        FreeBSD 2.2.x
>Organization:
Department of Training & Industrial Relations
>Environment:

	FreeBSD 2.2.x

>Description:

	FreeBSD 2.2.x /bin/sh functions don't return exit
	values as expected with a Bourne (compatible) shell.

	Traditional Bourne shells implement the "return" command as
	follows (this from the Solaris 2.5 man page):

	return [ n ]
	  Causes a function to exit  with  the  return  value
	  specified by n.  If n is omitted, the return status
	  is that of the last command executed.

	The FreeBSD 2.2.x /bin/sh doesn't does not, when n is
	omitted, return the status of the last command executed.

	This bug was not present in 2.1.5, nor 2.1.7.

	I discovered it while running the configure scripts for 
	Sam Leffer's HylaFAX and tiff library.

>How-To-Repeat:

	Script started on Tue May 13 08:33:18 1997
	$ uname -a
	FreeBSD scrubber.devetir.qld.gov.au 2.2-STABLE FreeBSD 2.2-STABLE #0: Thu May  1 18:41:39 EST 1997     wjh@scrubber.devetir.qld.gov.au:/usr/src/sys/compile/SCRUBBER  i386

	$ set
	PS1=$ 
	PS2=> 
	PATH=/bin:/usr/bin:/usr/local/bin
	IFS=    

	$ cat bug.sh
	#
	fail()
	{
	    false
	    return      # /bin/sh returns zero, wrong.
	}

	fail
	status=$?

	case $status in
	    0)  echo "shell broken, return status is $status"
		;;
	    *)  echo "shell OK, return status is $status"
		;;
	esac

	$ /bin/sh bug.sh
	shell broken, return status is 0

	$ /usr/local/bin/bash bug.sh
	shell OK, return status is 1

	$ /usr/local/bin/ksh bug.sh
	shell OK, return status is 1

	$ ^D
	Script done on Tue May 13 08:34:01 1997


>Fix:
	
	Use bash or ksh


Phil
--                                             Phil Chadwick
Email:  syspmc@dtir.qld.gov.au       ,-_|\     Supervisor, UNIX Support
Phone:  +61 7 3247 9239             /     *    Department of Training
Fax:    +61 7 3247 9111             \_,-._/    and Industrial Relations
                                         v
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: fenner 
State-Changed-When: Tue May 13 09:33:18 PDT 1997 
State-Changed-Why:  
Duplicate for bin/3388. 
>Unformatted:
