makefile:变量值中的尾随空格
我正在GNU make手册中阅读以下内容:makefile:变量值中的尾随空格,makefile,spaces,trailing,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 t
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,如下所示“
执行“make”时,输出仅为“hi”,在“hi”和下划线之间只有一个空格。为什么没有四个空格
谢谢,当
make
执行此脚本时,它不会将变量传递给echo,而是将$(foo)
替换为foo
的值
因此,实际执行的脚本是echo hi…..(点用于澄清)
在解析echo
的参数时,空白被忽略
可以将双引号括起来,使其作为字符串输出
echo "$(foo)_"
是的,是shell“吞下”了空间,我知道了。非常感谢!
echo "$(foo)_"