[pm-h] use of $$ versus $ in makefile and bash

Russell L. Harris rlharris at oplink.net
Thu Aug 30 13:33:57 PDT 2007


* G. Wade Johnson <gwadej at anomaly.org> [070830 07:28]:
> On Wed, 29 Aug 2007 17:12:55 -0500
> "Russell L. Harris" <rlharris at oplink.net> wrote:
> 
>> I am puzzled concerning the use of the symbols "$" and "$$" in a
>> makefile.  I do not understand why "$$" is required in some instances,
>> and "$" in other instances.
> 
> According to "Managing Project with make" by Oram and Talbott, $$ in
> make causes a $ to be used in the command instead of being evaluated
> as part of a make variable.

Thanks for an explanation which makes sense; the GNU Make manual is
ambiguous, to say the least:

    "To substitute a variable's value, write a dollar sign followed by
    the name of the variable in parentheses or braces: either `$(foo)'
    or `${foo}' is a valid reference to the variable foo. This special
    significance of `$' is why you must write `$$' to have the effect
    of a single dollar sign in a file name or command." (from section
    6.1)

The authors of such manuals seem never to test the manual by giving it
to someone unfamiliar with the subject and asking him to flag passages
which are not clear.


 
>> EXAMPLE 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
>> 
>>     -(for d in ${SYMLINKDIR};                            \
>>      do                                                  \
>>          pushd $$d &&                                    \
>>              ln -sf $(addprefix ../,${SYMLINKTARGET}) .; \
>>          popd;                                           \
>>      done;)

In the case of a variable name for which there is no possibility of
expansion (or there is such a thing?), would not the following be
equivalent?

    -(for d in ${SYMLINKDIR};                          \
    do                                                 \
        pushd $(d) &&                                  \
           ln -sf $(addprefix ../,${SYMLINKTARGET}) .; \
        popd;                                          \
    done;)

RLH


More information about the Houston mailing list