Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: for loop question
- X-seq: zsh-users 19315
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Subject: Re: for loop question
- Date: Mon, 03 Nov 2014 00:24:11 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1414970652; bh=hILA3hD0RxMmIJu1Ph6BbG/bUwxYaSb5rMKSPHn94TI=; h=cc:In-reply-to:From:References:To:Subject:Date:From:Subject; b=Yzo0ORq7DK5CyMmCy4A3LHeybVZao8pFV7PWSUEYx7I5LYa4Wp0JYMPJRQNLtsUfM+T9xIIjBYt9wfudwOdmiRU2nA16V7RijuKYdf2vka4LXn+uY8ajwwnc7hRT4jnTxAvGJRMDr8Bf08MH0qyzdM3Tc7kq9oA2KWCk+rYuqEJN606ZgZRYYtkUiSlxsDAF0D0+s1PX1H20L1DBrm4wKXtoxgTf1w3VuqNLQ6Za9VLP3Nhw/9jAWVJGuMGz0mxcYO9PQDvJ0tx8bPMVOX7/COzI+1SHsmn4AQe8mHwgWqugsd3SoTdRVk1yPvQjR3a9AkfNCASJslB2Vp+t1nuohQ==
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=G2arrpqWlfGqWTVl16DU1s3D4sDKrN/hFXwXnWmxETuUjAWd6lrxymVXtvGkMPxxZ0MKUmtJWB8IgSIp/OX1wRQU64VVqKkZj6H2idXAh2GluVpQO+qvYnrfSfFt7lLMnWSZZ1taMSyJBNAGDGZWg0TBLaTWcZd7AyCiY+Auh6iOIUbATewMvUO3XxtttFSN6mHuSjQLgUOs4p0f3tB/p/2CsZ/TebtQurthIxbh0Ps4Zp2I9VEE9tRW1694ltR9GwPWc/SDR6XQgnr0C3kZ+5YrDWv1UpNjhAYQIjT+o0b1KSVyKh21heBzNOXAIcDot7c278bow2CYLfmQ4MBxBA==;
- In-reply-to: <5456B3E6.4040907@eastlink.ca>
- 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
- References: <5456984A.3020001@eastlink.ca> <CAH+w=7aWS0xyS4CXRJBphDjesfUFQOsyJRMaG3RZRxmuj7xkOg__20885.3257158355$1414962125$gmane$org@mail.gmail.com> <20141102213713.GA4412@chaz.gmail.com> <5456B3E6.4040907@eastlink.ca>
Ray Andrews wrote:
> > You could with:
> >
> > for ((i=1; (z[$([ -n "$TLC[i]" ])0]),$? == 0; i++))
> > print -ru2 -- $TLC[i]
> >
> > (not that you would want to).
> No. That is pure sadism ;-) ;-)
>
> But it does show that 'for ((' CAN stop and digest ' [ -n "$TLC[i]" ]
> ' if it wants too,
> it just has to make it obscenely difficult. Why can't the truth test of
> a command just be taken
> as 'arithmetic' plain and simple?
Inside of (( ... )) is arithmetic context. So different syntax is valid
there. [ is just a command. Look at the error message you get if you put
it there:
% for ((; [ -f foo ] ; )) echo true
zsh: bad output format specification
Zsh sees the square brackets and in arithmetic context, square brackets
are used for selecting an output format, specifically a number base. For
example:
% echo $(( [#2] 37 ))
2#100101
There's also a command named true which just returns true. So what do
you think the following might do:
% for ((; true ;)) echo true!
This actually looks for the variable $true and interprets it as a
number.
As you can see, the syntaxes conflict. While we could add a simple way
to escape back into normal syntax from arithmetic syntax, it'd be no
nicer than the existing alternatives.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author