From owner-freebsd-questions@FreeBSD.ORG Thu Jul 10 15:49:43 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81E281065682 for ; Thu, 10 Jul 2008 15:49:43 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 869D38FC17 for ; Thu, 10 Jul 2008 15:49:42 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (adsl100-172.kln.forthnet.gr [77.49.107.172]) (authenticated bits=128) by igloo.linux.gr (8.14.3/8.14.3/Debian-4) with ESMTP id m6AFnL1c028214 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 10 Jul 2008 18:49:27 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.2/8.14.2) with ESMTP id m6AFnLQd035320; Thu, 10 Jul 2008 18:49:21 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.2/8.14.2/Submit) id m6AFnIVn035319; Thu, 10 Jul 2008 18:49:18 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: Malcolm Kay References: <20080709172513.GA51206@mech-cluster238.men.bris.ac.uk> <200807101354.46321.malcolm.kay@internode.on.net> <200807101415.51455.fbsd.questions@rachie.is-a-geek.net> <200807110018.43081.malcolm.kay@internode.on.net> Date: Thu, 10 Jul 2008 18:49:17 +0300 In-Reply-To: <200807110018.43081.malcolm.kay@internode.on.net> (Malcolm Kay's message of "Fri, 11 Jul 2008 00:18:42 +0930") Message-ID: <87lk09sps2.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: m6AFnL1c028214 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.764, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.64, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: Anton Shterenlikht , Mel , freebsd-questions@freebsd.org Subject: Re: snippet of configure script - explain please X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jul 2008 15:49:43 -0000 On Fri, 11 Jul 2008 00:18:42 +0930, Malcolm Kay wrote: > On Thu, 10 Jul 2008 09:45 pm, Mel wrote: >> On Thursday 10 July 2008 06:24:46 Malcolm Kay wrote: >> >> > > 9255 if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; >> > > then >> > >> > I find this line somewhat strange as I've not been able >> > to find documentation for the expansion of ${parameter+set} under the >> > Bourne shell. (nor bash, nor ksh) >> > ***************************************************** >> > Presumably someone out there knows where to find it? >> > ***************************************************** >> >> It's shorthand for ${paramter:+set}, so if unset, you get "", otherwise you >> get "set": >> $ echo ${foo+set} >> >> $ echo ${HOME+set} >> set > > So it appears; but is it stated anywhere that this shorthand is > legitimate? I find it quite frequently arising from the GNU > configuring tools but haven't found it elsewhere. It's legitimate. > Is it a deliberate shorthand or just a consequence of the way sh and > bash happen to have been programmed? In other words is it a safe > shorthand? The shorthand version would work too: if "${foo+set}" = 'set' ; then bar fi The interesting bits in the Autoconf generated code are, however, the side-effects of the expression: * ${ac_var} is set to the name of the variable to check. * The `ac_var' variable is expanded *twice* in the check. It is expanded once before eval runs, to get the _name_ of the variable to check, and then eval sees something like "${foo+set}". * The assignment to `ac_var' is done inside a { ... } pair of brackets; not in parentheses. This means that the rest of the script can keep using ${ac_var} to find the name of the `autoconf variable' this part of the script has set (the assignment to ac_var happens in the current shell, and not in a sub-process).