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

[PATCH] don't exit shell on [[ -o invalid@option ]]



Does it make sense for [[ -o invalid@option ]] to exit the shell with an
error message?

Other shells with '[[' (bash, ksh93 and pdksh/mksh variants) quietly
return an unsuccessful status for a non-existent shell option. That
behaviour makes more sense to me because of:

(1) backwards compatibility: a script that uses '[[' to test if a shell
option introduced in a recent zsh is set, would still work on an older
zsh that doesn't have that shell option.

(2) cross-shell compatibility: treating a non-existent option as not set
would make it easier to write a script that works on bash, ksh93, and
pdksh/mksh as well as zsh.

The attached patch brings zsh in line with those other shells. Up to you
to decide what to do with it...

- Martijn
diff --git a/Src/cond.c b/Src/cond.c
index b9a47ce..5eb59b2 100644
--- a/Src/cond.c
+++ b/Src/cond.c
@@ -492,7 +492,7 @@ dolstat(char *s)
 
 
 /*
- * optison returns evalcond-friendly statuses (true, false, error).
+ * optison returns evalcond-friendly statuses (true, false).
  */
 
 /**/
@@ -506,8 +506,7 @@ optison(char *name, char *s)
     else
 	i = optlookup(s);
     if (!i) {
-	zwarnnam(name, "no such option: %s", s);
-	return 2;
+	return 1;
     } else if(i < 0)
 	return !unset(-i);
     else


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