我正在阅读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'和下划线之间只有一个空格。为什么没有四个空格?
谢谢,
答案 0 :(得分:3)
当make
执行此脚本时,它不会将变量传递给echo,而是将$(foo)
替换为foo
的值。
所以执行的实际脚本是echo hi...._
(点是为了澄清)。
在解析echo
的参数时,只会忽略空格。
你可以加上双引号使其输出为字符串。
echo "$(foo)_"