What is the meaning of a double dollar sign in bash/Makefile?

后端 未结 2 712
無奈伤痛
無奈伤痛 2020-12-03 02:29

When inserting a shell script inside a Makefile we have (?) to use a double dollar sign ($$) to make reference to variables. Why is that so?

for number in 1          


        
2条回答
  •  有刺的猬
    2020-12-03 03:16

    As per gnu make official doc:

    Variable and function references in recipes have identical syntax and semantics to references elsewhere in the makefile. They also have the same quoting rules: if you want a dollar sign to appear in your recipe, you must double it (‘$$’). For shells like the default shell, that use dollar signs to introduce variables, it’s important to keep clear in your mind whether the variable you want to reference is a make variable (use a single dollar sign) or a shell variable (use two dollar signs).

    So in short:

    • makefile variable => use a single dollar sign
    • shell variable => use two dollar signs

提交回复
热议问题