From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22042 invoked by alias); 4 Sep 2013 19:09:46 -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: X-Seq: 31696 Received: (qmail 16097 invoked from network); 4 Sep 2013 19:09:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 209.85.215.178 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=x8R2B2bWxnoPn0gJmsZ7t5TlDh3Nk2FcO/sUOqVA3i4=; b=bs6rllIds1/+CeamRNWqn3EgxCptJb5Lg75X7P4cpnOvb4U9KfAUD7DSlrmbz6pCs5 PiX7zA6TICe0Wp9DfacemXOvs8dqNeeA/g4f2h9zWRGUwZ1TAHFxczsOKQKetiMkMz74 jm8VBY+SgnJmO9qWOjCAlaLZyHoSc0N6CbZGs3RvLIdUJSjYpTie4/s5iBc857vh5kIU fYGA4joTze4Kq9JS85x2bPU5eKAOtzD4qQiFgvxfAGP8JdXyCuZs8wAwnPMEyUPofJyI wIi++21Vs75nI2NOLh1EFE/+HAEkUwmPesuMMaWMPyiDdzl8NfopearxFKdQTPCfE7O5 dNvg== X-Gm-Message-State: ALoCoQkzy/GHsS9HNPpCjccLtefSmE78+Dmc545yLRDEIe8gn0suDaYzXlcKaCLPxKZlS329/faf X-Received: by 10.14.221.195 with SMTP id r43mr5803818eep.59.1378321773531; Wed, 04 Sep 2013 12:09:33 -0700 (PDT) X-ProxyUser-IP: 86.6.30.159 Date: Wed, 4 Sep 2013 20:09:29 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Builtin test and parsing of conditionals Message-ID: <20130904200929.5028f433@pws-pc.ntlworld.com> In-Reply-To: <130904103940.ZM28454@torch.brasslantern.com> References: <130904091503.ZM28369@torch.brasslantern.com> <20130904173159.19c55cd1@pwslap01u.europe.root.pri> <130904103940.ZM28454@torch.brasslantern.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 04 Sep 2013 10:39:40 -0700 Bart Schaefer wrote: > On Sep 4, 5:31pm, Peter Stephenson wrote: > } On Wed, 04 Sep 2013 09:15:03 -0700 > } Bart Schaefer wrote: > } > According to some discussion on the austin-group (POSIX) mailing list, > } > the following: > } > > } > test ! -a ! > } > test ! -o ! > } > test ! = ! > } > > } > should all be parsed as comparing the string "!" to the string "!", but > } > zsh gets this right only in the last case. > > Sorry, perhaps I should have been clearer: "! -a !" means to compare the > truth value "!" to the truth value of "!". But "truth value" in "test" > is the same as "non-empty string" (true) and "empty string" (false) [not > 0 or 1 as numeric values], so the -a operator is still comparing two > strings. OK, this looks straightforward enough. diff --git a/Src/parse.c b/Src/parse.c index 0c2a458..f0d0855 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -2088,9 +2088,17 @@ par_cond_2(void) } } if (tok == BANG) { - condlex(); - ecadd(WCB_COND(COND_NOT, 0)); - return par_cond_2(); + /* + * In "test" compatibility mode, "! -a ..." and "! -o ..." + * are treated as "[string] [and] ..." and "[string] [or] ...". + */ + if (!(condlex == testlex && *testargs && + (!strcmp(*testargs, "-a") || !strcmp(*testargs, "-o")))) + { + condlex(); + ecadd(WCB_COND(COND_NOT, 0)); + return par_cond_2(); + } } if (tok == INPAR) { int r; diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst index 494261e..8562519 100644 --- a/Test/C02cond.ztst +++ b/Test/C02cond.ztst @@ -324,6 +324,27 @@ F:Failures in these cases do not indicate a problem in the shell. > fi >} + weirdies=( + '! -a !' + '! -o !' + '! -a' + '! -o' + '! -a ! -a !' + '! = !' + '! !') + for w in $weirdies; do + eval test $w + print $? + done +0:test compatability weirdness: treat ! as a string sometimes +>0 +>0 +>1 +>0 +>0 +>0 +>1 + %clean # This works around a bug in rm -f in some versions of Cygwin chmod 644 unmodish -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/