From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: Michael Hwang <michael.a.hwang@gmail.com>
Cc: Mikael Magnusson <mikachu@gmail.com>,
zsh workers <zsh-workers@zsh.org>,
brandon@ifup.org
Subject: Re: [[ 0 =~ 1 || 1 = 0 ]] returns true
Date: Sat, 9 Oct 2010 18:17:01 -0400 [thread overview]
Message-ID: <20101009221700.GA60765@redoubt.spodhuis.org> (raw)
In-Reply-To: <AANLkTim6KnxvKXbJmUQrUqm+mCBMU=y2maB0PitOfBfC@mail.gmail.com>
On 2010-10-09 at 16:06 -0400, Michael Hwang wrote:
> % set -x
> % [[ 0 =~ 1 || 1 = 0 ]]
> +zsh:2> [[ 0 -regex-match 1 || ! 1 == 0 ]]
> % [[ 0 =~ 1 || 1 == 1 || 1 = 0 ]]
> +zsh:3> [[ 0 -regex-match 1 || ! 1 == 1 ]]
> % [[ 0 =~ 1 || 1 == 1 || 1 = 1 || 1 = 1 || 1 = 1 ]]
> +zsh:4> [[ 0 -regex-match 1 || ! 1 == 1 ]]
>
> It appears that zsh thinks it needs to invert the second conditional
> expression. Also, zsh seems to drop more than two conditional
> expressions.
The dropping is short-circuiting, the same as in all shell evaluation of
&& and ||. The shell stops once it knows enough to know the answer. So
false to the left of && will stop, and true to the left of || will stop.
% [[ 1 == 1 && 3 == 2 && 4 == 4 && sb == sb ]]
+zsh:12> [[ 1 == 1 && 3 == 2 ]]
% [[ 1 == 1 && 3 != 2 && 4 == 4 && sb == sb ]]
+zsh:13> [[ 1 == 1 && 3 != 2 && 4 == 4 && sb == sb ]]
So the issue appears to just be what the OP wrote, that =~ is messing up
&&/|| by inserting a sense inversion.
% [[ 1 =~ 0 || 1 == 1 ]]
+zsh:18> [[ 1 -regex-match 0 || ! 1 == 1 ]]
% [[ 1 -regex-match 0 || 1 == 1 ]]
+zsh:19> [[ 1 -regex-match 0 || 1 == 1 ]]
So it's related to use of =~ rather than -regex-match. It's independent
of whether or not zsh/pcre is loaded. So this is probably a bug which I
introduced when I wrote the =~ syntax support. Looking now.
-Phil
next prev parent reply other threads:[~2010-10-09 22:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-09 17:29 Mikael Magnusson
2010-10-09 20:06 ` Michael Hwang
2010-10-09 22:17 ` Phil Pennock [this message]
2010-11-02 16:34 ` Brandon Philips
2010-11-02 20:41 ` Mikael Magnusson
2010-11-02 23:37 ` Phil Pennock
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101009221700.GA60765@redoubt.spodhuis.org \
--to=zsh-workers+phil.pennock@spodhuis.org \
--cc=brandon@ifup.org \
--cc=michael.a.hwang@gmail.com \
--cc=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).