From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25608 invoked by alias); 2 Nov 2014 22:42:01 -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: 19313 Received: (qmail 169 invoked from network); 2 Nov 2014 22:41:48 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Authority-Analysis: v=2.1 cv=AduIQRnG c=1 sm=1 tr=0 a=WX1zAfUMD62odRRZjfQOeg==:117 a=WX1zAfUMD62odRRZjfQOeg==:17 a=gmhVCtT3eHoA:10 a=N659UExz7-8A:10 a=3KRDz1TD2F8K9okKwiwA:9 a=pILNOxqGKmIA:10 Message-id: <5456B3E6.4040907@eastlink.ca> Date: Sun, 02 Nov 2014 14:44:54 -0800 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.1.2 MIME-version: 1.0 To: zsh-users@zsh.org Subject: Re: for loop question References: <5456984A.3020001@eastlink.ca> <20141102213713.GA4412@chaz.gmail.com> In-reply-to: <20141102213713.GA4412@chaz.gmail.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 11/02/2014 01:37 PM, Stephane Chazelas 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? $ for ((; 1 ;)) echo true! true! true! true! ..... $ for ((; 0 ;)) echo true! [nothing] .... so why/how is it that the return value of a ' [] ' test is NOT either 1 or 0? Thanks for these, there is much to learn from them: > 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]}" >