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

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



Op 11-11-17 om 12:45 schreef Peter Stephenson:
> On Fri, 10 Nov 2017 14:37:17 -0800
> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>> We could certainly suppress the error in emulation modes given that's
>> what other shells do.  Further, I'm not strongly invested in the current
>> behavior even for native mode, but we should consider the ramifications.
> 
> It's not clear if it matters in practice rather than theory, no.  The
> test failing is probably usually good enough.
> 
> We could attach it to POSIXBUILTINS as that does control some aspects of
> reutrn / exit behaviour, and [[ ... ]] behaves like a specially parsed
> builtin.

Something like this?

Seems a bit wrong as this is not POSIX at all. Also, POSIXBUILTINS makes
'set -o' exit the shell on an invalid option, which is the opposite
effect. But I can't find a better shell option either.

- M.
diff --git a/Doc/Zsh/cond.yo b/Doc/Zsh/cond.yo
index e08fc0d..0ea5fc1 100644
--- a/Doc/Zsh/cond.yo
+++ b/Doc/Zsh/cond.yo
@@ -45,6 +45,8 @@ item(tt(-o) var(option))(
 true if option named var(option) is on.  var(option)
 may be a single character, in which case it is a single letter option name.
 (See noderef(Specifying Options).)
+If the var(option) does not exist, the shell exits with an error message,
+unless the shell option tt(POSIX_BUILTINS) is set.
 )
 item(tt(-p) var(file))(
 true if var(file) exists and is a FIFO special file (named pipe).
diff --git a/Src/cond.c b/Src/cond.c
index b9a47ce..814f4b0 100644
--- a/Src/cond.c
+++ b/Src/cond.c
@@ -506,6 +506,8 @@ optison(char *name, char *s)
     else
 	i = optlookup(s);
     if (!i) {
+	if (isset(POSIXBUILTINS))
+	   return 1; /* act like bash and *ksh */
 	zwarnnam(name, "no such option: %s", s);
 	return 2;
     } else if(i < 0)


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