From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15188 invoked by alias); 13 Aug 2011 00:24:44 -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: 16206 Received: (qmail 15410 invoked from network); 13 Aug 2011 00:24:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) 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.1 Received-SPF: none (ns1.primenet.com.au: domain at micahelliott.com does not designate permitted sender hosts) MIME-Version: 1.0 Sender: mde@micahelliott.com From: Micah Elliott Date: Fri, 12 Aug 2011 17:24:14 -0700 X-Google-Sender-Auth: 2Ubbk4kZvxoZSvjyLZBD2VdpbDg Message-ID: Subject: Idiom for booleans To: zsh-users@zsh.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi! I'm trying to figure out if the $+ expansion, as in ${+param}, is worth making use of. What idiom do you use for it? I could see it as a boolean for testing flags. As in: % verbosity=3Dhigh myscript.zsh ... (( $+verbosity )) && print chatty chatty % unset verbosity # uh-oh % (( $+verbosity )) && print chatty # should this work? ((: command not found I did see this idiom used in the Zsh Guide (http://zsh.sourceforge.net/Guide/zshguide03.html as: (( OPTIND > 1 )) && shift $(( OPTIND - 1 )) ) -- is that a bug? I suppose it boils down to understanding (explanation welcome here): % (( 0 )) ((: command not found % (( 1 )) # ok Wrapping in "if" makes it work too, but just feels tedious: % if (( 0 )); then print i say nothing; fi ---- I could make the boolean work by adding a fall-thru: % (( $+verbosity )) && print chatty || : but that feels rotten. Or I could use: % [[ $+verbosity =3D=3D 1 ]] && print chatty but that doesn't seem any better than the more common and simpler: % [[ -n $verbosity ]] && print chatty So is there some concise idiomatic way of making use of $+ ? Or is this last line the better way to make such tests? -- twitter:@Membean=C2=A0 |=C2=A0 email:Micah@Membean.com=C2=A0 |=C2=A0 http:/= /Membean.com Remember your words with Membean. Three free days of learning! GO SIGN UP.