[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in function return statement in while subshell

From: Pierre Gaston
Subject: Re: Bug in function return statement in while subshell
Date: Tue, 30 Jul 2013 13:15:59 +0300

On Tue, Jul 30, 2013 at 12:51 PM, Chris Down <address@hidden> wrote:
> On 2013-07-30 12:45, Pierre Gaston wrote:
>> On Tue, Jul 30, 2013 at 12:29 PM, Chris Down <address@hidden> wrote:
>> > On 2013-07-30 12:11, Pierre Gaston wrote:
>> >> what about things like this: foo () (  return 1; )
>> >
>> > Except in this case, the return has a valid context. I don't see how it's 
>> > really
>> > comparable to the represented case.
>> It's a return in a subshell in a function, i don't think the
>> comparison is far fetched.
> Except in this case the function and the subshell are linked constructs.
>> I see what you mean,  but that raises the question of what's a valid context.
>> Should we make a special case if the subshell is the "outer" compound
>> command of a function?
> I am not totally convinced that this is a special case since the subshell
> basically becomes the declaration.
>> The same thing with by break and continue example:
>> while :;do ( while :;do break 2; done);echo foo;done
>> Should this raise an error? is the break in a loop context? what's a
>> loop context?
> Well, breaking to an undef level is already allowed and doesn't return an 
> error
> (although I think that's not your point).
>         $ while :; do break 999; done
>         $ echo $?
>         0
> If you mean "should it break the outer loop", then my opinion is no.

There are 2 loop levels in my example, but break only exit the subshell.

My point is that now, return, break, continue all do the same thing:
exit the subshell if they are inside one.
This is a uniform behavior that can be easily documented.

Raising an error would mean more cases and it may be a good idea to
think about all the cases and what that implies.
eg another one:
 foo () { if command; then return 1;else return 2;fi & }
Should this raise an error? it doesn't look so alien to me

while :;do ( if true;then continue;else echo again;fi);done # here
continue seems ok, with an error I would be forced to use "exit"
while :;do ( if true;then break;else echo again;fi); echo bar;done #
here it doesn't seem so great, an error would help.

mksh raises an error for break and continue, but behaves like bash for
the function

reply via email to

[Prev in Thread] Current Thread [Next in Thread]