zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] don't exit shell on [[ -o invalid@option ]]
@ 2017-11-10 18:24 Martijn Dekker
  2017-11-10 18:53 ` Eric Cook
  2017-11-10 22:37 ` Bart Schaefer
  0 siblings, 2 replies; 19+ messages in thread
From: Martijn Dekker @ 2017-11-10 18:24 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 744 bytes --]

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

[-- Attachment #2: dont-exit-on-testing-invalid-option.patch --]
[-- Type: text/plain, Size: 504 bytes --]

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-12-03  7:28 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-10 18:24 [PATCH] don't exit shell on [[ -o invalid@option ]] Martijn Dekker
2017-11-10 18:53 ` Eric Cook
2017-11-10 19:03   ` Martijn Dekker
2017-11-10 22:37 ` Bart Schaefer
2017-11-11 12:45   ` Peter Stephenson
2017-11-11 19:01     ` Martijn Dekker
2017-11-11 23:19       ` Bart Schaefer
2017-11-12 19:56         ` Peter Stephenson
2017-11-14 12:26           ` Daniel Shahaf
2017-11-14 13:22             ` Martijn Dekker
2017-11-14 23:52               ` Daniel Shahaf
2017-11-16  0:52                 ` Martijn Dekker
2017-11-18 18:22                   ` Daniel Shahaf
2017-11-19 14:46                     ` Martijn Dekker
2017-11-19 19:41                     ` Bart Schaefer
2017-11-19 19:53                       ` Peter Stephenson
2017-11-20  1:22                         ` Daniel Shahaf
2017-11-24 21:50                           ` Daniel Shahaf
2017-12-03  7:28                             ` Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).