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 exit execution of while loop instead of
function.
What would you like to see happen? You're in a subshell: the function
can't return, since this is not the shell that called it. Do you want
parent and child shells both continuing execution after the function call?
Chet
As Chris said, some error, because return is not in function.
Example:
f1() {
: | while :; do return 3; done
echo $?
return 1
}
echo $?
f1; echo $?
return 2
Looks like the bash doesn't restore the i'm-in-function indicator when
running compound command (like while or if) in functions' subshell.
I'm not sure exactly what you mean by this, since the `return' call in
the pipeline inside the function completes without an error. Bash
prints an error message due to the `return 2' not occurring while in
a function.
Chet
My point is that the `return 3' in while loop is in subshell and will
not return from the function and it can be perceived similarly to
`return 2' statement. Why the `return 3' doesn't introduce an error? It
is not returning from a function. It just naively knows that it is in
function?
RR