From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18145 invoked by alias); 4 Nov 2014 05:34:39 -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: 19327 Received: (qmail 9880 invoked from network); 4 Nov 2014 05:34:38 -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=HFAqn+/zf1X/gxAyCqSGKQ==:117 a=HFAqn+/zf1X/gxAyCqSGKQ==:17 a=gmhVCtT3eHoA:10 a=N659UExz7-8A:10 a=ZgSH7zlTQfFM49445FsA:9 a=pILNOxqGKmIA:10 Message-id: <5458743B.2000204@eastlink.ca> Date: Mon, 03 Nov 2014 22:37:47 -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> <20141104015639.GA2871@localhost.localdomain> <141103184338.ZM32221@torch.brasslantern.com> In-reply-to: <141103184338.ZM32221@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 11/03/2014 06:43 PM, Bart Schaefer wrote: > The 0 is appended because [ -n "$TLC[i]" ] does not produce any output, But in if [ -n "$TLC[i]" ] ... the test must surely produce an answer of some sort. Yes or no. If that answer is not acceptable as 'arithmetic', then what is it? ! $([ -n "$TLC[i]" ]; echo $?) 'echo $?' seems to receive a one or a zero, and that's 'arithmetic', so why does ! $([ -n "$TLC[i]" ]); ... not do exactly the same thing? Why do we need 'echo' to cough up a testable number? What does the '$?' do but carry the return value of the test? And what would break if the test just returned it's own return value with no need for help from 'echo $?' to restate it? When we use the 'if' form above, we don't need the help of 'echo $?' so why do we need it inside 'for (('? It seems like a pointless limitation. Maybe a trivial limitation, but still pointless. Indeed: [ -n "$TLC[i]" ] && echo "Yup, there's something in there" ... so the [] test doesn't even need 'if' to work, it *does* produce a testable return value, and IMHO that's 'arithmetic', so it should work in 'for (('. 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. Sure, but we get used to using '!' to reverse true/false, no? You hafta wonder, tho, how that convention ever got started. '0' is 'false', yet functions return '0' on success. AFAIK it has always been like that.