Subject: Re: NetBSD master CVS tree commits
To: Greg A. Woods <woods@kuma.web.net>
From: Bruce Albrecht <Bruce.Albrecht@seag.fingerhut.com>
List: current-users
Date: 06/04/1996 16:40:36
Greg A. Woods writes:
 > > Modified Files:
 > > 	eval.c 
 > > Log Message:
 > > Fix PR/2504: return with no args returns 0 instead of the return value of
 > > the previous command in functions
 >  
 > I think this PR was in error.

I wrote this PR, and maybe the fix, I submitted one with my PR.  I was
seeing an exit value of zero when a function returned with a return
statement with no parameters, but all of my references (except for the
O'Reilly ksh book) indicated that this was wrong. I don't have a copy
of P1003.2, but if you can tell me where it's online, I'll check it
out.

Does the following excerpt really talk about the return command, or
just function exit status?
 > 
 > From P1003.2/D11.2 section 3.9.5, p. 276:
 > 
 >  Exit_Status
 > 
 >  The exit status of a function definition shall be zero if the function
 >  was declared successfully; otherwise, it shall be greater than zero.  The
 >  exit status of a function invocation shall be the exit status of the last
 >  command executed by the function.
 > 
 > (I have a hopy of Draft 12 too, I think, but it has a "gunzip:
 > POSIX-D12.tar.gz: invalid compressed data--crc error")
 > 
 > This also doesn't seem to be a bug according to current implementations,
 > such as my SunOS shells:

What I was seeing with NetBSD was the following:

Execute the following file:
t1() {
 echo "in t1"
 return 29
}
t2() {
 echo "in t2"
 t1
 return
}
echo "in main"
t2
echo "returned $?"

When I run this, I get:
sh ~bruce/treturn
in main
in t2
in t1
returned 0

Are you saying that without the patched eval.c, /bin/sh on NetBSD is
returning a non-zero value for the above or for your example below?
If it is, then I'd like to figure out why my versions of NetBSD
(Amiga, 1.1 and 1.2_ALPHA) are not functioning as expected.

 > 
 > 14:<woods@vex> $ uname -a
 > SunOS vex.net 5.5 Generic sun4m sparc SUNW,SPARCstation-20
 > 14:<woods@vex> $ sh
 > $ testit ()
 > > {
 > >       false
 > > > }
 > > ^?
 > $ testit ()
 > > {
 > >       false
 > >       return
 > > }
 > $ testit
 > $ echo $?
 > 255
 > $ 14:<woods@vex> $ ksh
 > 14:<woods@vex> $ testit ()
 > > {
 > >         false
 > >         return
 > > }
 > 14:<woods@vex> $ testit
 > 14:<woods@vex> $ echo $?
 > 1
 > 14:<woods@vex> $ 
 > 
 > 
 > $ uname -a
 > SunOS very 4.1.1_U1 2 sun3
 > $ testit ()
 > > {
 > >       false
 > >       return
 > > }
 > $ testit
 > $ echo $?
 > 1
 > $ 
 > 
 > -- 
 > 							Greg A. Woods
 > 
 > +1 416 443-1734			VE3TCP			robohack!woods
 > Planix, Inc. <woods@planix.com>; Secrets Of The Weird <woods@weird.com>
 >