[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: Mon, 29 Jul 2013 19:04:29 +0300

On Mon, Jul 29, 2013 at 6:44 PM, Greg Wooledge <address@hidden> wrote:
> On Mon, Jul 29, 2013 at 06:36:58PM +0300, Pierre Gaston wrote:
>> it's not clear (like it is for, say, exit) what the relationship
>> between return and process is.
>> I guess most people expect it to not care about subshells and just
>> execute the statement after the function call.
> "Most people" barely know what a subshell is.

Sure, but even If I know what it is,  it's still not clear why return
would only exit the process
since it sounds something more related to the concept of "functions".

The same thing is true for break eg:

while :;do ( while :;do break 2; done);echo foo;done

break seems more tied to the number of "done" than to the concept of process.
Intuitively I would not expect foo to be printed

>> I'm not sure how the case foo () { return & echo foo; } would fit though.
> My personal opinion is that this is horrible code and you should be
> ashamed of it, if you wrote it.  The return is executed in a background
> job, so it does nothing except cause immediate termination of the job.

It's not real code and it's asking for trouble, but does this mean it
should not be considered at all?
I think it illustrates the "conflict" between the shell syntax and the
idea of subshells.

> I don't see any compelling argument to change the way Bash handles this.

Maybe, maybe it just need a word or two in the documentation

reply via email to

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