Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [BUG] Condition in [[ doesn't fire, with "if" it fires
- X-seq: zsh-users 22521
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: Zsh Users' List <zsh-users@xxxxxxx>
- Subject: Re: [BUG] Condition in [[ doesn't fire, with "if" it fires
- Date: Wed, 01 Mar 2017 12:01:32 +0000
- Cms-type: 201P
- In-reply-to: <20170228115158.727f67ff@pwslap01u.europe.root.pri>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
- References: <1488280289.2878360.895324176.3971EE76@webmail.messagingengine.com> <CGME20170228112804epcas2p2e241ff0013d6ac1cae21987a41442ce8@epcas2p2.samsung.com> <1488281256.2881475.895357184.6106CE5C@webmail.messagingengine.com> <20170228115158.727f67ff@pwslap01u.europe.root.pri>
On Tue, 28 Feb 2017 11:51:58 +0000
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Tue, 28 Feb 2017 03:27:36 -0800
> Sebastian Gniazdowski <psprint3@xxxxxxxxxxxx> wrote:
> > Checked that even:
> >
> > [[ "below" = "below" ]] && (( line ++ )) || (( line = stborder ))
> >
> > doesn't fire. In the same way. It is the false option that is fired:
>
> && and || don't work the way they do in C, they are simply evaluated
> left to right in a symmetric fashion.
While that's true, I suppose I ought to point out, for anyone trying to
learn something from this, that in this particular case the logic
happens to work the same as C. zsh does { X && Y } || Z because of left
to right evaluation, C does (X && Y) || Z beause of precedence.
The oddity causing the problem was the (( ... )) return status non-zero,
rather than the logical ordering, which is a rather different point.
Where it's very different from C is
X || Y && Z
which is effectively { X || Y } && Z in zsh, because it's simply left
to right, and X || (Y && Z) in C because of precedence. There's nothing
to stop you writing X || { Y && Z } in zsh to group explicitly, however.
Now back to normal service.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author