Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: for loop question
- X-seq: zsh-users 19317
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Ray Andrews <rayandrews@xxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: for loop question
- Date: Mon, 3 Nov 2014 02:53:48 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=a1YRK52rwyF3jec2CY3Z/DX2FY+KWmUEg/63bEKe1Kc=; b=AKT0Pr5rHMny/L7ZziG2s7fahA+Xu2NKzLqYDVN7T/mV0srKcc0deWnqUQrHALeprr nRBhB64/V9YATup2yC5tHRJF4LHIfOSnBfbI+9dqPyisvaWfX0P/M2DhxKD01i2u4IN3 44Za/9CqU6149WmAv/K8bRVGypxS1M/I2rRYtqWe1gIN156alYvUQ64y9TPy4wtCZeck GYvSZwk5AKJd2ejsu/G2dP/4hHnJdEP/iROPT80nwZVHOWzRctGn86ctJSlCqokSPnR0 qetOaJqPQao4Fm51dg6BQsGkwGinSRzx8xl/RsMRcxIvLOeUzNy4uV1HGugYqxXRuVHx hyIA==
- In-reply-to: <20141102213713.GA4412@chaz.gmail.com>
- 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>
On Sun, Nov 2, 2014 at 10:37 PM, Stephane Chazelas
<stephane.chazelas@xxxxxxxxx> wrote:
> 2014-11-02 13:00:14 -0800, Bart Schaefer:
>> > I've fiddled around with various modifications but it seems to dislike "
>> [ -n "$TLC[i]" ] "
>> > even though the 'while' loop is happy with it. That expression evaluates
>> to true or
>> > false, does it not? So why won't 'for' swallow it?
>>
>> The double parents (( )) are special arithmetic syntax. You can't use an
>> ordinary shell command like "test" ( for which "[" is an alias) inside that
>> construct.
>
> You could with:
>
> for ((i=1; (z[$([ -n "$TLC[i]" ])0]),$? == 0; i++))
> print -ru2 -- $TLC[i]
>
> (not that you would want to).
>
> Here, you more likely want:
>
> for i ("$TLC[@]") print -ru2 -- $i
>
> or
>
> print -rlu2 -- "$TLC[@]"
>
> or:
>
> for ((i = 1; i <= $#TLC; i++)) print -ru2 -- $TLC[i]
>
>
> Or (to print only till the first empty element):
>
> for ((i = 1; $#TLC[i]; i++)) print -ru2 -- "$TLC[i]"
>
> Or:
>
> print -rlu2 -- "${(@)TLC[1,TLC[(i)]-1]}"
We might want to avoid using obscure mixes of the discouraged
alternate syntax with syntax that depends on short_loops being set,
when helping people who are asking questions about basic syntax. :)
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author