From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29206 invoked by alias); 3 Nov 2014 01:54:08 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19317 Received: (qmail 160 invoked from network); 3 Nov 2014 01:53:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 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== MIME-Version: 1.0 X-Received: by 10.50.6.100 with SMTP id z4mr13288988igz.37.1414979628694; Sun, 02 Nov 2014 17:53:48 -0800 (PST) In-Reply-To: <20141102213713.GA4412@chaz.gmail.com> References: <5456984A.3020001@eastlink.ca> <20141102213713.GA4412@chaz.gmail.com> Date: Mon, 3 Nov 2014 02:53:48 +0100 Message-ID: Subject: Re: for loop question From: Mikael Magnusson To: Bart Schaefer , Ray Andrews , Zsh Users Content-Type: text/plain; charset=UTF-8 On Sun, Nov 2, 2014 at 10:37 PM, 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] > > (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