Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: for loop question
- X-seq: zsh-users 19312
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: for loop question
- Date: Sun, 2 Nov 2014 21:37:13 +0000
- Cc: Ray Andrews <rayandrews@xxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=wBumEXxbAb7PAgIryycQR0cRj7as2V9JW8yJ+rP72N4=; b=nIpk6guTBIq3QLfltGJ6M53ucGkVSHhGTJXdQSH8EwR/Bj5OQKtVKlJgXjH0EgO3+X ZKg94BaKcNEBcQOLiNR8n+OEpj506qzEz7QbOb4ElDak4U8aQ8V9/bEyEBjOmNcQngzB PiUkYCo55lHCaguYXJN1ZJUt0KypLqJ2Ih2faXK6nw3e9Lg/vbZZ13ra+EHeePjn4PfW Im8jPwQ7hTSVoxTLfbnu7ctwkjQPWrstG8zpCCBhaa6Qtas+hBI8BHWXHuwfyeEoITmW c9NoCCAfMnzX6rq7C6Z8uh11nxZyVZCbMv0uQhV1QE37hyUMk1v+DsknMmpoHeSmonK9 8qiQ==
- In-reply-to: <CAH+w=7aWS0xyS4CXRJBphDjesfUFQOsyJRMaG3RZRxmuj7xkOg__20885.3257158355$1414962125$gmane$org@mail.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>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Ray Andrews <rayandrews@xxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- 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>
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]}"
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author