Bash Makefile错误与消息一起退出
当错误发生时,是否有任何方法可以输出错误消息。让我们详细讨论一下,我想知道一个文件内容是否等于另一个文件内容。如果不等于,则应退出Bash Makefile错误与消息一起退出,bash,shell,makefile,gnu-make,Bash,Shell,Makefile,Gnu Make,当错误发生时,是否有任何方法可以输出错误消息。让我们详细讨论一下,我想知道一个文件内容是否等于另一个文件内容。如果不等于,则应退出make并输出错误消息 test: cmp --silent tmp/test.txt tmp/test_de.txt || (error DecryptFile is different from original) 当tmp/test.txt不等于tmp/test_de.txt时,输出为: cmp --silent tmp/test.txt tmp
make
并输出错误消息
test:
cmp --silent tmp/test.txt tmp/test_de.txt || (error DecryptFile is different from original)
当tmp/test.txt
不等于tmp/test_de.txt
时,输出为:
cmp --silent tmp/test.txt tmp/test_de.txt | (error DecryptFile is different from original)
/bin/sh: 1: error: not found
makefile:38: recipe for target 'test' failed
make: *** [test] Error 127
/bin/sh:1:错误:未找到
结果不是我想要的。我只是想要这样的错误消息:
makefile:38: *** missing separator. Stop.
您可以使用
退出
。(
和)
可以包含多个命令:
cmp --silent tmp/test.txt tmp/test_de.txt || (echo "DecryptFile is different from original"; exit 1)
也许
error
指的是,但是您应该编写$(error
…)
,而不仅仅是(error
…)
,并且您不能这样使用它(在shell命令中)。所以你真的应该使用echo
和exit
as。也许您可以将echo
重定向到stderr(例如echo message 2>&1
或echo message>/dev/stderr
)
$(error
…)
内置可以(并且经常)与GNU make一起使用。您想要这样的东西吗:cmp--silent tmp/test.txt tmp/test|de.txt | echo“error decrypt文件与原始文件不同”
?如果是这样,make
不会错误退出。顺便说一下,echo message>/dev/stderr
是什么意思?重定向到stderr后,我可以使用/dev/stderr
做什么。