From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1222 invoked by alias); 18 Nov 2017 18:23:16 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42031 Received: (qmail 29996 invoked by uid 1010); 18 Nov 2017 18:23:16 -0000 X-Qmail-Scanner-Diagnostics: from out4-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.28):SA:0(-1.9/5.0):. Processed in 9.890977 secs); 18 Nov 2017 18:23:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=PxT8UY N/uPk/9dctdZYKznT9ejx4UL8bKcUWnfTSbVA=; b=eyEtQ4tlSYzoeD5xIqMyeq PxU0vQgs4JxUGZS2a3EmQU7eo5SdckBJNrzJeKV5nksp9LewASx+/l7mVxHtciD1 w+LffkQDhi5bp5xYgsAcPIQb/t5vkKUn7X5x+RpbGG9wLsQG6aVcTtL4hT4lWSEh N1jufPQB7TOIOFzcneJCpHEiEf61D8sffLiQLgcMRLpIAwIx5uK33ZNTqKsPg6yy q7HQCub9+tE/E08g4nBf7aBCP4uSrkaf5LmuPpsEJmnWHwwYH7eWkhjgFYFd6z2N Hs0EoMFxtXYWrjUfMSez/VmQCit3FNkeFmXtINRZhj19Q0Gu3n6aMfxSd0WjJTYg == DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=PxT8UY N/uPk/9dctdZYKznT9ejx4UL8bKcUWnfTSbVA=; b=rhlUI3XXd0cORVEyRkMc+U 3B88h1tCeUACVX5wibqs1WslYKHdE3GVUo9Lnh1PQ58UdmvpQKLovHJrd8Ked2VS pM+W3LtSckA0mNxd9j+Z7qxLuLxrlp7UpKB0oLt5fk27W5MIAJyJJCF1NFPXk5xi NADaZF+qupvsEyFNeQOD7oB5DTapCw6FmYi6bavudcMFNJanHAVf+4yYMKVdijLu vmC8MQYlVMNwCGVKeCnWVmgbX+l+95rVO+kVUP6prWy+CVyDozjUZIDM52BJbse3 N2wdFx2xzPhfr9ERa8X+6QexNNyuAWXf6urAe5D2HD03xoJivNk9+g0tnP5DgfNQ == X-ME-Sender: Message-Id: <1511029379.709069.1176966800.1BF7416A@webmail.messagingengine.com> From: Daniel Shahaf To: zsh-workers@zsh.org MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-4ef04c51 References: <0d6faa9a-fb69-8343-9630-a60d8f1bee0a@inlv.org> <171110143717.ZM16244@torch.brasslantern.com> <20171111124528.035a70ac@ntlworld.com> <38275e86-81c7-dbf8-544e-b0a399a4461d@inlv.org> <171111151905.ZM20139@torch.brasslantern.com> <20171112195657.74fb0b8a@ntlworld.com> <20171114122619.kqa4i2sth66mafrs@tarpaulin.shahaf.local2> <20171114235249.egcynklamldfcogv@tarpaulin.shahaf.local2> Subject: Re: [PATCH] don't exit shell on [[ -o invalid@option ]] In-Reply-To: Date: Sat, 18 Nov 2017 18:22:59 +0000 Martijn Dekker wrote on Thu, 16 Nov 2017 02:52 +0200: > Op 15-11-17 om 01:52 schreef Daniel Shahaf: > > Okay, so how about if we demoted the fatal error to a warning? Like > > this: > >=20 > > % [[ -o not_an_option ]] || echo This gets run > > zsh: [[: no such option: not_an_option > > This gets run > > %=20 >=20 > I think that would be fine, as well as returning status 2 along with it. >=20 > I do think the warning (and the status 2) should be suppressed if > POSIX_IDENTIFIERS or some other emulation-relevant shell option is > active, so that 'emulate ksh' and 'emulate sh' reproduce ksh behaviour. How about the following. It uses status 3 because status 2 currently means "syntax error in [[" and I didn't want to overload that; and it uses POSIX_BUILTINS because that seemed more closely related than POSIX_IDENTIFIERS. Consider it a work in progress, i.e., particulars are still malleable. There are good arguments in favour of all sides here=E2=80=A6 (incumbent behaviour, Martijn's patch, this patch) Cheers, Daniel diff --git a/Doc/Zsh/cond.yo b/Doc/Zsh/cond.yo index e08fc0d36..4ca132a26 100644 --- a/Doc/Zsh/cond.yo +++ b/Doc/Zsh/cond.yo @@ -45,6 +45,10 @@ 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).) + +When no option named var(option) exists, and the tt(POSIX_BUILTINS) option +hasn't been set, return 3 with a warning. If that option is set, return 1 +with no warning. ) item(tt(-p) var(file))( true if var(file) exists and is a FIFO special file (named pipe). diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 28155d796..d043cf398 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -2169,6 +2169,9 @@ command found in the path. Furthermore, the tt(getopts) builtin behaves in a POSIX-compatible fashion in that the associated variable tt(OPTIND) is not made local to functions. + +Moreover, the warning and special exit code from +tt([[ -o )var(non_existent_option)tt( ]]) are suppressed. ) pindex(POSIX_IDENTIFIERS) pindex(NO_POSIX_IDENTIFIERS) 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". */ =20 /**/ @@ -86,10 +87,10 @@ case COND_NOT: if (tracingcond) fprintf(xtrerr, " %s", condstr[ctype]); ret =3D evalcond(state, fromtest); - if (ret =3D=3D 2) - return ret; - else + if (ret =3D=3D 0 || ret =3D=3D 1) return !ret; + else + return ret; case COND_AND: if (!(ret =3D evalcond(state, fromtest))) { if (tracingcond) @@ -100,7 +101,8 @@ case COND_AND: return ret; } case COND_OR: - if ((ret =3D evalcond(state, fromtest)) =3D=3D 1) { + ret =3D evalcond(state, fromtest); + if (ret =3D=3D 1 || ret =3D=3D 3) { if (tracingcond) fprintf(xtrerr, " %s", condstr[ctype]); goto rec; @@ -506,8 +508,12 @@ optison(char *name, char *s) else i =3D 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 diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 38525016c..04e1ca8f2 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -440,6 +440,23 @@ F:Failures in these cases do not indicate a problem in= the shell. > [[ 'a' =3D=3D 'b' || 'b' =3D 'c' || 'c' !=3D 'd' ]] >} =20 + (setopt posixbuiltins; eval '[[ -o invalidoption ]]; echo set: $?'; echo= "no warning" >&2) + (unsetopt posixbuiltins; [[ -o invalidoption ]]; echo unset: $?) + [[ -o invalidoption || -n nonempty ]]; echo "in disjunction, true: $?" + [[ -o invalidoption || -z nonempty ]]; echo "in disjunction, false: $?" + [[ ! -o invalidoption ]]; echo "negated: $?" +0:-o invalidoption +>set: 1 +?no warning +>unset: 3 +?(eval):2: no such option: invalidoption +>in disjunction, true: 0 +?(eval):3: no such option: invalidoption +>in disjunction, false: 1 +?(eval):4: no such option: invalidoption +>negated: 3 +?(eval):5: no such option: invalidoption + %clean # This works around a bug in rm -f in some versions of Cygwin chmod 644 unmodish