On Fri, Nov 04, 2005 at 11:36:02AM -0800, Debian Bug Tracking System wrote:
[...]
> It has been closed by one of the developers, namely
> Gerrit Pape <[EMAIL PROTECTED]> (reply to [EMAIL PROTECTED]).
[...]
> > On Sun, Oct 09, 2005 at 07:55:19PM +0100, Stephane Chazelas wrote:
> > > f() {
> > >   while return 2; do :; done
> > > }
> > > 
> > > f
> > > echo "$?"
> > > 
> > > The above script outputs "0" while it should output "2".
> > > 
> > > Same goes for:
> > > 
> > > dash -c 'while return 2; do :; done'
> > > 
> > > Same with "until" instead of "while"
> > 
> > Hi Stephane, I think the return code 0 is just fine, please see
> > 
> >  
> > http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_04_09
> >  
> > http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_04_10
> > 
> > I'm about to close this bug.
> 
> Ok, closing it.
[...]

Hi Gerrit, sorry I didn't receive your initial e-mail.

The SUSv3sections you refer to speak of the exit status of the
while loops. That doesn't apply in my script example where I
talk of the *function* exit status. "return" when called within a
function should always set the function exit status to the
argument it is passed, regardless of whether it is called within
a loop or not.

All other POSIX shells behave like that.

http://www.opengroup.org/onlinepubs/009695399/utilities/return.html

It is definitely a bug to me. I've not tested it, but I had had
a look at the *BSD versions of "sh" from which dash is derived,
and noticed there had been modifications in that area. They
might have been aware of that bug, you may want to check with
them.

In the later case "dash -c 'while return 2; ...'" I agree that
POSIX states that it is unspecified (as "return" is not called
from a function or a dotted script), but not setting the exit
status to 2 while causing the shell to return wouldn't make any
sense, as "return" was explicitely called with 2, and there
wouldn't be any other reason why one would call "return 2" there
except to set the exit code to 2, and that would be inconsistent
with the behavior where "return" is called from within a
function.

Best regards,
Stéphane

Reply via email to