GNU 在配方中生成变量和 shell 变量
GNU make variable and shell variable in recipe
我有点混淆配方中的 make 变量和 shell 变量。
由于每一行食谱都被解释为 shell,我可以进行 shell 变量赋值吗?
以下是示例:
.ONESHELL:
all:
param="hello"
echo $(param)
//--------------------
没有输出...
我知道我们可以对变量赋值使用 eval,但它看起来像 make 变量。
我怎样才能执行正常的 shell 变量赋值,我想保留 shell 命令 return 值。
谢谢
$(param)
由 GNU make 扩展。要使其扩展 shell,请执行 $${param}
。 Using Variables in Recipes:
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).
我有点混淆配方中的 make 变量和 shell 变量。
由于每一行食谱都被解释为 shell,我可以进行 shell 变量赋值吗?
以下是示例:
.ONESHELL:
all:
param="hello"
echo $(param)
//--------------------
没有输出...
我知道我们可以对变量赋值使用 eval,但它看起来像 make 变量。
我怎样才能执行正常的 shell 变量赋值,我想保留 shell 命令 return 值。
谢谢
$(param)
由 GNU make 扩展。要使其扩展 shell,请执行 $${param}
。 Using Variables in Recipes:
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).