Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [[ 0 =~ 1 || 1 = 0 ]] returns true
- X-seq: zsh-workers 28337
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: Michael Hwang <michael.a.hwang@xxxxxxxxx>
- Subject: Re: [[ 0 =~ 1 || 1 = 0 ]] returns true
- Date: Sat, 9 Oct 2010 18:17:01 -0400
- Cc: Mikael Magnusson <mikachu@xxxxxxxxx>, zsh workers <zsh-workers@xxxxxxx>, brandon@xxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d200912; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=euf0gLfDV7OCGyd1QYKchBscnn0QqHclqNvl6Pbl3Qg=; b=g7RqbCzc97W6ODGblwKTcslXxta5w0k+2d3Xcm8jqRvIw6vu2DHxF3Dg9sBTcxovoJerfWjqmG0myz4kl32cOd1kD962N2Il+HpkizTW9l3JQ/JCBHjzVppjtRLjNhI6BjvZaAU36mg6aZR9YmF4iP63FUHRokHPYLJlw4G/B+k=;
- In-reply-to: <AANLkTim6KnxvKXbJmUQrUqm+mCBMU=y2maB0PitOfBfC@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mail-followup-to: Michael Hwang <michael.a.hwang@xxxxxxxxx>, Mikael Magnusson <mikachu@xxxxxxxxx>, zsh workers <zsh-workers@xxxxxxx>, brandon@xxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <AANLkTi=G-8Hro4iqv_cNorbRiJCxXt-XmFifeyBNwLof@xxxxxxxxxxxxxx> <AANLkTim6KnxvKXbJmUQrUqm+mCBMU=y2maB0PitOfBfC@xxxxxxxxxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author