From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24842 invoked by alias); 4 Nov 2014 05:01:51 -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: 19326 Received: (qmail 8759 invoked from network); 4 Nov 2014 05:01:47 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.2 Date: Tue, 4 Nov 2014 12:51:25 +0800 From: Han Pingtian To: zsh-users@zsh.org Subject: Re: for loop question Message-ID: <20141104045125.GC2871@localhost.localdomain> Mail-Followup-To: zsh-users@zsh.org References: <5456984A.3020001@eastlink.ca> <20141102213713.GA4412@chaz.gmail.com> <20141104015639.GA2871@localhost.localdomain> <141103184338.ZM32221@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <141103184338.ZM32221@torch.brasslantern.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14110404-0029-0000-0000-000001043B97 On Mon, Nov 03, 2014 at 06:43:38PM -0800, Bart Schaefer wrote: > } 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. Cool! Thanks a lot!