From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9209 invoked by alias); 6 Aug 2012 23:12:49 -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: 17199 Received: (qmail 25656 invoked from network); 6 Aug 2012 23:12: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=-1.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at luo.ma does not designate permitted sender hosts) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:x-originating-ip:in-reply-to:references:from :date:x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=8w21owJSDWdITMEN6Zr00p7OxPhaeqZpCaDpkC8k6OI=; b=CznsZC0pf7xMEh70RyLnUOQ+2o/wPP+ahPiKcRSAgcAu2xV7kmFS0K7eONjBC3aRVB 89IggMSxtigiDfSHmUsqP4B2uqZxUugA4iIvB6ei1/DDChUoONI8RopQlnqxPz+++c4H p9myKe0aVt/8c6LP5msta+AmEzesGGB4KlkiNudnm3shNpKljGsVFLx47yQdvBNKew4r 8yPkHJyWDVUOgiHijz5d0LX6LxtUQlK46J90T0oW/JJHkELVboLgfz/nR7HT9paybxME +SIa7CAZlVJ/R/bzZxKpoKYl6RXyCiC2aGDEihkHD6YVIki3i6XlAPCnCayC2Ic9MC8x EHAg== MIME-Version: 1.0 Sender: tj@luo.ma X-Originating-IP: [108.72.106.118] In-Reply-To: References: From: TjL Date: Mon, 6 Aug 2012 19:12:04 -0400 X-Google-Sender-Auth: foTRIUGVn6sdfHJMtKBAaFv7iiQ Message-ID: Subject: Re: equivalent of "if (( $+commands[FOO] ))" for functions? To: "Benjamin R. Haskell" Cc: Zsh Users Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQk57JZkXOZAlNuwn87HFtvaztwx2C+3ZslgBe7o2kapRyeEQ6Xt0GR8R5ikAvF0sZcBCbBU On Mon, Aug 6, 2012 at 6:38 PM, Benjamin R. Haskell wrote: > In case you've only seen the idiom you're using, and didn't have an > explanation: > > $+param expands to 0 if param is unset, and 1 if it's set. The double > parentheses: (( ... )) just make the conditional "mathy" (so that non-ze= ro > is true). So, you can use this with your own associative arrays, too: > > typeset -A some_array > some_array+=3D( foo some-foo-thing ) > if (( $+some_array[foo] )) > then > echo yay > fi Ah, that's helpful, thanks. Indeed I have just been copy/pasting this without really knowing how it worked. Hrm=85 so=85 I often do something like this to do different things based on the exit status of a given command 'foo' For example: foo EXIT=3D"$?" if [ "$EXIT" =3D "0" ] then # do whatever else echo "$0: failed (\$EXIT =3D $EXIT)" exit 1 fi Is there a way to do something like that with $+param? I tried this: EXIT+=3D( test -d ~/etc ) if (( $+EXIT[test] )) then echo yes else echo no fi thinking that it would say 'yes' if 'test -d' exited with status =3D 0 or 'no' with any other status, but that didn't seem to work (I always seem to get no even if 'test -d' should return 0. So I assume that I'm misunderstanding something, possibly trying to make apple pie uses oranges and wondering why it doesn't taste right. TjL