Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] Condition in [[ doesn't fire, with "if" it fires



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