help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] subtle "break" strangeness


From: Greg Wooledge
Subject: Re: [Help-bash] subtle "break" strangeness
Date: Tue, 3 Sep 2013 11:03:03 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Sep 03, 2013 at 04:53:01PM +0200, Chris Down wrote:
> On 2013-09-03 10:16, Chet Ramey wrote:
> > How can it?  The subshell started to run `break' understands that it is
> > running in a loop -- it inherits that understanding from its parent --
> > but there is no way to communicate the `breaking' status from a child
> > back to its parent.
> 
> Like I said in the other thread, I think that we should reset context-specific
> flags in children (except for when the child is the entirety of the function
> definition, in the case of function definitions).

Obviously you can't just say "if the current process is a subshell,
then issue a warning if break is used".  Because the entire loop might
be in a subshell, and then break would just act as expected.

Are you proposing that bash should keep track of the "subshell depth"
at all times, and also keep track of what the subshell depth was each
time a loop was created, so that when 'break' is called, it can compare
the current depth to the depth of the loop it's trying to break out of?

That seems like overkill to me -- wasted resources on bookkeeping, when
it's a programmer error that can be avoided simply by not writing the
program incorrectly in the first place.  Bash doesn't need to be any
slower.



reply via email to

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