snippet of configure script - explain please

Thomas Dickey dickey at radix.net
Thu Jul 10 14:59:11 UTC 2008


On Fri, Jul 11, 2008 at 12:18:42AM +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

it's interesting, but config.log would probably show the actual check
that was made to fill in the shell variable...

> > > 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.
> 
> 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?

man sh on Solaris for instance:

     ${parameter:+word}
           If parameter is set and is non-null, substitute  word;
           otherwise substitute nothing.

     In the above, word is not evaluated unless it is to be  used
     as  the  substituted string, so that, in the following exam-
     ple, pwd is executed only if d is not set or is null:

          echo ${d:-`pwd`}



SunOS 5.8            Last change: 9 May 1997                    4

The same feature is on OpenBSD - I don't have FreeBSD at hand, but
think it's likely to be found in the manpage - I just looked for

	/+.*}

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20080710/be7fa367/attachment.pgp


More information about the freebsd-questions mailing list