Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: for loop question
- X-seq: zsh-users 19322
- From: Han Pingtian <hanpt@xxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: for loop question
- Date: Tue, 4 Nov 2014 10:29:42 +0800
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Ray Andrews <rayandrews@xxxxxxxxxxx>
- In-reply-to: <20141104015639.GA2871@localhost.localdomain>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: zsh-users@xxxxxxx, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Ray Andrews <rayandrews@xxxxxxxxxxx>
- 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> <20141104015639.GA2871@localhost.localdomain>
On Tue, Nov 04, 2014 at 09:56:39AM +0800, Han Pingtian wrote:
> On Sun, Nov 02, 2014 at 09:37:13PM +0000, Stephane Chazelas 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]
> >
> What does the (z[$([ -n "$TLC[i]" ])0]) mean, please?
>
I think I have got the meaning of it. The goal is to run
'[ -n "$TLC[i]" ]' in a math context, so embed the testing in the
subscript of 'z[..]'. The 'z' will be explained as a array in this math
context, the value of '$z[...]' is ignored, only the result of
'[ -n "$TLC[i]" ]' is compared with 0.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author