makefile:变量值中的尾随空格

时间:2012-11-12 10:27:49

标签: makefile spaces trailing

我正在阅读GNU make手册中的以下内容:

if you do not want any whitespace characters at the end of your variable value, 
you must remember not to put a random comment on the end of the line after some whitespace, such as this:

 dir := /foo/bar    # directory to put the frobs in
Here the value of the variable dir is ‘/foo/bar    ’ (with four trailing spaces), 
which was probably not the intention. (Imagine something like ‘$(dir)/file’ with this definition!)

我试过一个简单的makefile,如下面的“

foo := hi    # four trailing spaces
all:
    @echo $(foo)_

执行'make'时,输出只是'hi _','hi'和下划线之间只有一个空格。为什么没有四个空格?

谢谢,

1 个答案:

答案 0 :(得分:3)

make执行此脚本时,它不会将变量传递给echo,而是将$(foo)替换为foo的值。

所以执行的实际脚本是echo hi...._(点是为了澄清)。

在解析echo的参数时,只会忽略空格。

你可以加上双引号使其输出为字符串。

echo "$(foo)_"
相关问题