Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Makefile:echo未正确打印_Linux_Makefile_Echo - Fatal编程技术网

Linux Makefile:echo未正确打印

Linux Makefile:echo未正确打印,linux,makefile,echo,Linux,Makefile,Echo,我有以下命令 $ 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”后,输出为: $

我有以下命令

$ 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{

如何正确地使用
Makefile
使用
echo
写入文件?

make
只向shell发送一个配方(分割长行除外),而不解释它。所以是你的外壳解释了它

因此,shell运行这个
echo
printf
命令。像bash或zsh这样的shell对echo和printf使用内置命令(如果您没有明确要求使用
/bin/echo
命令)

shell之间的内置命令的行为也有所不同。更重要的是,您可以使用一个shell来运行交互式命令,而
make
使用不同的shell(默认情况下/bin/sh)来处理交互命令

下面是壳之间差异的示例。当我在
bash
中运行echo\\newcommand时,我得到:

$ echo \\newcommand
\newcommand
$ echo \\newcommand

ewcommand
当我在
zsh
中运行
echo\\newcommand
时,我得到:

$ echo \\newcommand
\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