Re: Bug in function return statement in while subshell

2013-07-30 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 7/30/13 10:30 AM, Chris Down wrote: > On 2013-07-30 10:18, Greg Wooledge wrote: >> 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

Re: Bug in function return statement in while subshell

2013-07-30 Thread Chris Down
On 2013-07-30 10:18, Greg Wooledge wrote: > 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

Re: Bug in function return statement in while subshell

2013-07-30 Thread Greg Wooledge
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

Re: Bug in function return statement in while subshell

2013-07-30 Thread Roman Rakus
On 07/30/2013 03:50 PM, Chet Ramey wrote: On 7/29/13 1:15 PM, Roman Rakus wrote: On 07/29/2013 05:06 PM, Chet Ramey wrote: On 7/29/13 10:55 AM, Roman Rakus wrote: I didn't take a look on where the problem could be, but it is discussed on stackoverflow [1]. Looks like return builtin falsely ex

Re: Bug in function return statement in while subshell

2013-07-30 Thread Chet Ramey
On 7/29/13 1:15 PM, Roman Rakus wrote: > On 07/29/2013 05:06 PM, Chet Ramey wrote: >> On 7/29/13 10:55 AM, Roman Rakus wrote: >>> I didn't take a look on where the problem could be, but it is discussed on >>> stackoverflow [1]. >>> >>> Looks like return builtin falsely exit execution of while loop

Re: Bug in function return statement in while subshell

2013-07-30 Thread Greg Wooledge
On Tue, Jul 30, 2013 at 01:15:59PM +0300, Pierre Gaston wrote: > >> 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? The break occurs in a subshell, which means it cannot communicate what I presum

Re: Bug in function return statement in while subshell

2013-07-30 Thread Chris Down
On 2013-07-30 13:15, Pierre Gaston wrote: > There are 2 loop levels in my example, but break only exit the subshell. Yes, that's what I was saying. I think this should only exit the subshell (although I'd like to see break and its family returning errors when you are trying to operate on more loop

Re: Bug in function return statement in while subshell

2013-07-30 Thread Pierre Gaston
On Tue, Jul 30, 2013 at 12:51 PM, Chris Down wrote: > On 2013-07-30 12:45, Pierre Gaston wrote: >> On Tue, Jul 30, 2013 at 12:29 PM, Chris Down wrote: >> > On 2013-07-30 12:11, Pierre Gaston wrote: >> >> what about things like this: foo () ( return 1; ) >> > >> > Except in this case, the return

Re: Bug in function return statement in while subshell

2013-07-30 Thread Chris Down
On 2013-07-30 12:45, Pierre Gaston wrote: > On Tue, Jul 30, 2013 at 12:29 PM, Chris Down 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 > > co

Re: Bug in function return statement in while subshell

2013-07-30 Thread Pierre Gaston
On Tue, Jul 30, 2013 at 12:29 PM, Chris Down 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 su

Re: Bug in function return statement in while subshell

2013-07-30 Thread Chris Down
On 2013-07-29 17:05, Chris Down wrote: > On 29 Jul 2013 17:00, "Roman Rakus" wrote: > > > > I didn't take a look on where the problem could be, but it is discussed > on stackoverflow [1]. > > > > Looks like return builtin falsely exit execution of while loop instead of > function. > > Unless I'm r

Re: Bug in function return statement in while subshell

2013-07-30 Thread Chris Down
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. pgpeaKMNUypTl.pgp Description: PGP signature

Re: Bug in function return statement in while subshell

2013-07-30 Thread Pierre Gaston
On Mon, Jul 29, 2013 at 8:15 PM, Roman Rakus wrote: > On 07/29/2013 05:06 PM, Chet Ramey wrote: >> >> On 7/29/13 10:55 AM, Roman Rakus wrote: >>> >>> I didn't take a look on where the problem could be, but it is discussed >>> on >>> stackoverflow [1]. >>> >>> Looks like return builtin falsely exit

Re: Bug in function return statement in while subshell

2013-07-29 Thread Roman Rakus
On 07/29/2013 05:06 PM, Chet Ramey wrote: On 7/29/13 10:55 AM, Roman Rakus wrote: I didn't take a look on where the problem could be, but it is discussed on stackoverflow [1]. Looks like return builtin falsely exit execution of while loop instead of function. What would you like to see happen

Re: Bug in function return statement in while subshell

2013-07-29 Thread Pierre Gaston
On Mon, Jul 29, 2013 at 7:04 PM, Pierre Gaston wrote: > On Mon, Jul 29, 2013 at 6:44 PM, Greg Wooledge 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

Re: Bug in function return statement in while subshell

2013-07-29 Thread Pierre Gaston
On Mon, Jul 29, 2013 at 6:44 PM, Greg Wooledge 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 >> exec

Re: Bug in function return statement in while subshell

2013-07-29 Thread Greg Wooledge
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" bar

Re: Bug in function return statement in while subshell

2013-07-29 Thread Pierre Gaston
On Mon, Jul 29, 2013 at 6:06 PM, Chet Ramey wrote: > On 7/29/13 10:55 AM, Roman Rakus wrote: >> I didn't take a look on where the problem could be, but it is discussed on >> stackoverflow [1]. >> >> Looks like return builtin falsely exit execution of while loop instead of >> function. > > What wou

Re: Bug in function return statement in while subshell

2013-07-29 Thread Chet Ramey
On 7/29/13 10:55 AM, Roman Rakus wrote: > I didn't take a look on where the problem could be, but it is discussed on > stackoverflow [1]. > > Looks like return builtin falsely exit execution of while loop instead of > function. What would you like to see happen? You're in a subshell: the functio

Re: Bug in function return statement in while subshell

2013-07-29 Thread Chris Down
On 29 Jul 2013 17:00, "Roman Rakus" wrote: > > I didn't take a look on where the problem could be, but it is discussed on stackoverflow [1]. > > Looks like return builtin falsely exit execution of while loop instead of function. Unless I'm reading this wrongly, this seems like expected behaviour

Bug in function return statement in while subshell

2013-07-29 Thread Roman Rakus
I didn't take a look on where the problem could be, but it is discussed on stackoverflow [1]. Looks like return builtin falsely exit execution of while loop instead of function. [1] http://stackoverflow.com/questions/7109720/behavior-of-return-statement-in-bash-functions RR