[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: Greg Wooledge
Subject: Re: Bug in function return statement in while subshell
Date: Tue, 30 Jul 2013 10:18:27 -0400
User-agent: Mutt/

On Tue, Jul 30, 2013 at 04:12:07PM +0200, Roman Rakus wrote:
> >>f1() {
> >>     : | while :; do return 3; done
> >>     echo $?
> >>     return 1
> >>}
> >>echo $?
> >>f1; echo $?
> >>return 2

> My point is that the `return 3' in while loop is in subshell and will 
> not return from the function

Correct.  It will terminate the loop in the subshell.

> and it can be perceived similarly to 
> `return 2' statement.

I don't see how you "perceive" these things the same way.  One is inside
a function (albeit a fork()ed child process's copy of the function).
The other is outside of all functions.

> Why the `return 3' doesn't introduce an error?

Because it is occurring inside a function.

> It 
> is not returning from a function. It just naively knows that it is in 
> function?

After the fork() which creates the subshell, each of the two processes
(parent and child) is still within its own instance of the function.
The "return" command executed in the child causes the child's function
to terminate, but this does not cause the parent's function to terminate.

reply via email to

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