4

我正在阅读 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'和下划线之间只有一个空格。为什么没有四个空格?

谢谢,

4

1 回答 1

3

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

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

解析echo.

您可以使用双引号将其作为字符串输出。

echo "$(foo)_"
于 2012-11-12T10:49:48.367 回答