about summary refs log tree commit diff
path: root/Src/cond.c
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2017-11-24 22:09:41 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2017-11-24 22:10:27 +0000
commit77a39b57bf467812b9219ae6a84f2f71e6a50065 (patch)
tree99131cf303d38b18151623e4e4cdab2044005ba1 /Src/cond.c
parent487489c5225aee671077bc0ea257e5c460e675ef (diff)
downloadzsh-77a39b57bf467812b9219ae6a84f2f71e6a50065.tar.gz
zsh-77a39b57bf467812b9219ae6a84f2f71e6a50065.tar.xz
zsh-77a39b57bf467812b9219ae6a84f2f71e6a50065.zip
42031 + 42048: Make [[ -o invalidoption ]] a normal(ish) false value, rather than a syntax error.
Diffstat (limited to 'Src/cond.c')
-rw-r--r--Src/cond.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/Src/cond.c b/Src/cond.c
index b9a47cea5..9f13e07d7 100644
--- a/Src/cond.c
+++ b/Src/cond.c
@@ -61,7 +61,8 @@ static void cond_subst(char **strp, int glob_ok)
  * of functionality.
  *
  * Return status is the final shell status, i.e. 0 for true,
- * 1 for false and 2 for error.
+ * 1 for false, 2 for syntax error, 3 for "option in tested in
+ * -o does not exist".
  */
 
 /**/
@@ -86,10 +87,10 @@ evalcond(Estate state, char *fromtest)
 	if (tracingcond)
 	    fprintf(xtrerr, " %s", condstr[ctype]);
 	ret = evalcond(state, fromtest);
-	if (ret == 2)
-	    return ret;
-	else
+	if (ret == 0 || ret == 1)
 	    return !ret;
+	else
+	    return ret;
     case COND_AND:
 	if (!(ret = evalcond(state, fromtest))) {
 	    if (tracingcond)
@@ -100,7 +101,8 @@ evalcond(Estate state, char *fromtest)
 	    return ret;
 	}
     case COND_OR:
-	if ((ret = evalcond(state, fromtest)) == 1) {
+	ret = evalcond(state, fromtest);
+	if (ret == 1 || ret == 3) {
 	    if (tracingcond)
 		fprintf(xtrerr, " %s", condstr[ctype]);
 	    goto rec;
@@ -506,8 +508,12 @@ optison(char *name, char *s)
     else
 	i = optlookup(s);
     if (!i) {
-	zwarnnam(name, "no such option: %s", s);
-	return 2;
+	if (isset(POSIXBUILTINS))
+	    return 1;
+	else {
+	    zwarnnam(name, "no such option: %s", s);
+	    return 3;
+	}
     } else if(i < 0)
 	return !unset(-i);
     else