Some users find it confusing that exit and return in a pipe
construct do not affect the original shell, document it to help
them understand what is going on.
---
Sorry for the delay, it took me some time to get back to this.

 mksh.1 |   15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

--- a/mksh.1
+++ b/mksh.1
@@ -2927,6 +2927,10 @@ function.
 A function can be made to finish immediately using the
 .Ic return
 command; this may also be used to explicitly specify the exit status.
+Note that when called in a subshell,
+.Ic return
+will only exit that subshell and will not cause the original shell to exit
+a running function (see the while...read loop FAQ.)
 .Pp
 Functions defined with the
 .Ic function
@@ -3461,7 +3465,7 @@ Note that the Bourne shell differs here;
 it does pass these file descriptors on.
 .Pp
 .It Ic exit Op Ar status
-The shell exits with the specified exit status.
+The shell or subshell exits with the specified exit status.
 If
 .Ar status
 is not specified, the exit status is the current value of the
@@ -6741,6 +6745,15 @@ cannot be propagated if run in a pipelin
 bar \*(Ba baz \*(Ba while read foo; do ...; done
 .Ed
 .Pp
+.Ed
+Also note that
+.Ic exit
+in the inner loop will only exit the subshell and not the original shell.
+Likewise, if the code is inside a function,
+.Ic return
+in the inner loop will only exit the subshell and won't terminate the
+function.
+.Pp
 Use co-processes instead:
 .Bd -literal -offset indent
 bar \*(Ba baz \*(Ba&
-- 
Jean Delvare
SUSE L3 Support

Reply via email to