Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "continue -1" confuses zsh



Daniel Qarras <dqarras@xxxxxxxxx>:
[...]
> while [ 1 ]; do continue -1; done
> 
> confuses zsh: no errors are printed, the loop exits, but then no
> commands are executed anymore. Easy to reproduce:
> 
> localhost:~> echo foo
> foo
> localhost:~> while [ 1 ]; do continue -1; done
> localhost:~> echo foo                         
> localhost:~> 

I don't know what the actual reason for this reaction is, but:

As per SUSv3 for break and continue:

EXIT STATUS
    0  Successful completion.
   >0  The n value was not an unsigned decimal integer greater than or
       equal to 1.

So, IMHO a trivial fix for this is:


---
 Src/builtin.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index ee44b37..ae63da5 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -4443,6 +4443,9 @@ bin_break(char *name, char **argv, UNUSED(Options ops), int func)
 	nump = 1;
     }
 
+    if (num <= 0)
+	return 1;
+
     switch (func) {
     case BIN_CONTINUE:
 	if (!loops) {   /* continue is only permitted in loops */
-- 
1.6.0.1.90.g27a6e



Messages sorted by: Reverse Date, Date, Thread, Author