From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1IodBp-0007eD-Qm for garchives@archives.gentoo.org; Sun, 04 Nov 2007 10:58:50 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.14.1/8.14.0) with SMTP id lA4AvwtX000321; Sun, 4 Nov 2007 10:57:58 GMT Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by robin.gentoo.org (8.14.1/8.14.0) with ESMTP id lA4AtBuv029033 for ; Sun, 4 Nov 2007 10:55:12 GMT Received: from localhost (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 2E08B65947 for ; Sun, 4 Nov 2007 10:55:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at gentoo.org X-Spam-Score: -0.032 X-Spam-Level: X-Spam-Status: No, score=-0.032 required=5.5 tests=[AWL=0.500, BAYES_00=-2.599, RCVD_NUMERIC_HELO=2.067] Received: from smtp.gentoo.org ([127.0.0.1]) by localhost (smtp.gentoo.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zM9Kx3-8Uw-1 for ; Sun, 4 Nov 2007 10:55:11 +0000 (UTC) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id C0834656AA for ; Sun, 4 Nov 2007 10:55:09 +0000 (UTC) Received: from root by ciao.gmane.org with local (Exim 4.43) id 1Iod8A-0004s1-Mb for gentoo-dev@gentoo.org; Sun, 04 Nov 2007 10:55:02 +0000 Received: from 82.153.73.107 ([82.153.73.107]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 04 Nov 2007 10:55:02 +0000 Received: from slong by 82.153.73.107 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 04 Nov 2007 10:55:02 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: gentoo-dev@lists.gentoo.org From: Steve Long Subject: [gentoo-dev] Re: More general interface to use flags Followup-To: gmane.linux.gentoo.portage.devel Date: Sun, 04 Nov 2007 10:54:30 +0000 Message-ID: References: <472B29B9.50002@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@gentoo.org Reply-to: gentoo-dev@lists.gentoo.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 82.153.73.107 User-Agent: KNode/0.10.4 Sender: news Cc: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: 9bcac1ea-045e-43a5-96b7-cd67bb1fce79 X-Archives-Hash: a4e63bab9f58d14df29502992e79f2a3 Marijn Schouten (hkBst) wrote: > the current interface to use flags, useq, usev, use_with, use_enable, as > defined in /usr/lib/portage/bin/ebuild.sh lacks generality. The common > thing is testing a use flag and possibly echoing a string, but there is no > function that implements this common behaviour. > > I propose that we add such a function. Proposed name for the function is > "ifuse". > I like the overall API that is enabled (and that it doesn't break anything.) > I also propose to add the utility function "ifv" which is useful for > writing concise and clean code. > This one seems a bit light-weight to me, but if it makes your life easier, why not? One minor thing; -n is the default test, so: [[ $1 ]] is the same as [[ -n $1 ]] and: [[ ! $1 ]] is the same as [[ -z $1 ]] ''help test'' is very revealing, for those who haven't read it. ;-) Also, you need to add quotes to the echo'ed vars, as Mr Marples outlined: ifv() { [[ $1 ]] && echo "$2" || echo "$3" } If you don't, the vars will be split according to IFS, and treated as separate parameters, eg: ~ $ a=$'blah\nfoo' ~ $ echo "$a" blah foo ~ $ echo $a blah foo The following sums up the whole quoting issue IMO: "At its base, a shell is simply a macro processor that executes commands. The term macro processor means functionality where text and symbols are expanded to create larger expressions." http://tiswww.tis.case.edu/~chet/bash/bashref.html -- gentoo-dev@gentoo.org mailing list