Makefile`echo -n'不起作用 [英] Makefile `echo -n' not working
问题描述
我试图让我的Makefile回显文本而没有结尾的换行符,但是无法这样做.我在OS X上遇到了这种情况(在Linux上,一切正常.)
I am trying to have my Makefile echo text without the trailing new line, but am unable to. I am experiencing the behavior on OS X (on Linux everything works as expected).
a:
@echo -n "hello"
b:
@echo -n hello
c:
@/bin/echo -n "hello"
输出:
$make a
-n hello
$make b
hello$make c
hello$
换句话说,make a
被破坏了.到底是怎么回事? make是否使用内置回显?显然,双引号的出现改变了行为,但是为什么呢?
In other words, the make a
is broken. What exactly is happening? Is make using a built-in echo? Clearly the presence of the double quotes changes the behavior, but why?
由@chepner发现,使用makefile中/bin/echo
的完整路径可以正确理解-n标志.
As discovered by @chepner, using the full path to /bin/echo
in the makefile understands the -n flag correctly.
推荐答案
有关引号的某些内容使make
感到困惑.您的代码对我而言的行为相同,但以下各项按预期工作:
Something about the quotes confuses make
. Your code behaves the same for me, but the following works as expected:
help:
@echo -n Shouldn\'t print a newline
硬编码可执行文件的路径也可以:
Hardcoding the path to the executable also works:
help:
@/bin/echo -n "Shouldn't print a newline"
用于echo
的Mac OS X手册页在讨论外壳内置echo
的存在时,提到sh(1)
的echo
不支持-n
选项,但是失败了.向我解释(无论如何)为什么我的第一个替代方法有效.
The Mac OS X man page for echo
, while discussing the existence of shell built-in echo
s, mentions that the echo
of sh(1)
does not support the -n
option, but that fails to explain (to me, anyway) why my first alternative works.
确认make
在默认情况下正在使用sh
执行命令.在
Confirmation that make
is using sh
to execute the commands by default. In
SHELL = bash
help:
@echo -n "Shouldn't print a newline"
@echo -n Shouldn\'t print a newline
两个echo语句的行为相同(不打印换行符).因此,如果没有该变量,我们将bash
假装为sh
,但是对两行的评估不同.问题1:为什么?问题2:第二行是本地bash
回声还是/bin/echo
,而不是模拟的sh
echo
?
both echo statements behave the same (no newlines printed). So without that variable, we have bash
pretending to be sh
, but evaluating the two lines differently. Question 1: why? Question 2: is the second line the native bash
echo or /bin/echo
, rather than the emulated sh
echo
?
这篇关于Makefile`echo -n'不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!