On Fri, 11 Jul 2008 00:18:42 +0930, Malcolm Kay <[EMAIL PROTECTED]> 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). _______________________________________________ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"