Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 May 1997 14:11:59 +1000 (EST)
From:      Phil Chadwick <syspmc@dtir.qld.gov.au>
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/3587: Bug report for FreeBSD 2.2.x /bin/sh
Message-ID:  <199705130411.OAA14680@goblin.devetir.qld.gov.au>
Resent-Message-ID: <199705130420.VAA28034@hub.freebsd.org>

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

>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:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 12 21:20:01 PDT 1997
>Last-Modified:
>Originator:     Phil Chadwick
>Organization:
Department of Training & Industrial Relations
>Release:        FreeBSD 2.2.x
>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
>Audit-Trail:
>Unformatted:



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