From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9221 invoked by alias); 4 Nov 2014 02:44:02 -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: 19323 Received: (qmail 26688 invoked from network); 4 Nov 2014 02:44:00 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=GLe/yVJP c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=1CTQzo6BhnXhwo7JYBgA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <141103184338.ZM32221@torch.brasslantern.com> Date: Mon, 03 Nov 2014 18:43:38 -0800 In-reply-to: <20141104015639.GA2871@localhost.localdomain> Comments: In reply to Han Pingtian "Re: for loop question" (Nov 4, 9:56am) References: <5456984A.3020001@eastlink.ca> <20141102213713.GA4412@chaz.gmail.com> <20141104015639.GA2871@localhost.localdomain> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: for loop question MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Nov 4, 9:56am, Han Pingtian wrote: } } > for ((i=1; (z[$([ -n "$TLC[i]" ])0]),$? == 0; i++)) } > print -ru2 -- $TLC[i] } > } What does the (z[$([ -n "$TLC[i]" ])0]) mean, please? It's an overly-obfuscated way to write $([ -n "$TLC[i]" ]). The real work is the ",$?" part. z[...],$? is used to throw away the z[...] part and keep the value of $?. The value of $? comes from the side-effect of the $(...) inside the subscript of z[...]. The 0 is appended because [ -n "$TLC[i]" ] does not produce any output, but there has to be a valid number as the subscript, hence z[0]. This could be written a LOT more plainly as for ((i=1; $([ -n "$TLC[i]" ]; echo $?) == 0; i++)) without needing any more characters. If we're playing golf, for ((i=1; ! $([ "$TLC[i]" ]; echo $?); i++)) works too. Which, by the way, points out another reason you can't just use the exit status of a command in a math context: command success/failure are the reverse of true/false when taken as integer values.