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"; };
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}

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?

Anyway thanks for the clarification,

This syntax is certainly legitimate, and it is covered in the sh(1)
man page.  However, the relevant section talks mostly about the related


which means 'evaluate to null unless ${parameter} is unset or null, otherwise evaluate to 
"word"'.  Then there's a very small and easily
missed note to the effect:

 "In the parameter expansions shown previously, use of the colon in the
  format results in a test for a parameter that is unset or null; omission
  of the colon results in a test for a parameter that is only unset."

So ${parameter+word} means 'evaluate to null unless ${parameter} is unset,
otherwise evaluate to "word"'



Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                 Flat 3
PGP:     Ramsgate
                                                 Kent, CT11 9PW

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to