[英]Makefile: echo not properly printing
我有以下命令
$ echo \\newcommand{\\coverheight}{11.0in} > tmp
$ cat tmp
echo \\newcommand{\\coverheight}{11.0in} > tmp
但是当我在make文件中使用相同的echo
命令时,它没有正确写入文件。
# Makefile
all:
printf '\\newcommand{\\coverheight}{11.0in}' > tmp
运行`make'后,输出为:
$ cat tmp
ewcommand{
如何使用echo
使用Makefile
正确写入文件?
make
只是发送一个配方(除了分割长行)到你的shell并且不解释它。 所以你的shell解释它。
所以你的shell运行这个echo
和printf
命令。 像bash或zsh这样的shell使用echo和printf的内置命令(如果你没有明确地使用/bin/echo
命令)。
shell之间的内置命令行为之间存在差异。 更重要的是,您可以使用一个shell来运行交互式命令, make
使用不同的shell(默认情况下为/ bin / sh)来处理收件人。
以下是shell之间差异的示例。 当我在bash
运行echo \\\\newcommand
,我得到:
$ echo \\newcommand
\newcommand
当我在zsh
运行echo \\\\newcommand
,我得到:
$ echo \\newcommand
ewcommand
我怀疑你因此而得到不同的结果。 实际上printf '\\\\newcommand{\\\\coverheight}{11.0in}'
必须更正确,因为它使用强引号。
无论如何,在makefile中打印的一种方法似乎是使用外部命令/ bin / echo:
all:
command echo '\\newcommand{\\coverheight}{11.0in}' > tmp
或者使用您已经完成的强引用:
all:
printf '\\newcommand{\\coverheight}{11.0in}' > tmp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.