Bash 即使其中的一个操作失败,也要继续执行make命令
我正在寻找一种在发生错误失败时继续执行make命令的方法 我需要一种包装命令的方法,这样它就不会以退出代码1响应Bash 即使其中的一个操作失败,也要继续执行make命令,bash,shell,makefile,Bash,Shell,Makefile,我正在寻找一种在发生错误失败时继续执行make命令的方法 我需要一种包装命令的方法,这样它就不会以退出代码1响应 test: exit 1 ;\ echo 'hi' ;\ 我需要一种方法来包装这样的东西: example: somecommand && othercommand ;\ echo 'hi' ;\ test: rm fileDoesNotExist && echo foo || true echo bar
test:
exit 1 ;\
echo 'hi' ;\
我需要一种方法来包装这样的东西:
example:
somecommand && othercommand ;\
echo 'hi' ;\
test:
rm fileDoesNotExist && echo foo || true
echo bar
其中,somecommand
可以退出并显示1
(错误)而不运行othercommand
或运行othercommand的0
,应该执行以下操作:
test:
commandThatMayFail && otherCommand || true
echo hi
您可以这样尝试:
example:
somecommand && othercommand ;\
echo 'hi' ;\
test:
rm fileDoesNotExist && echo foo || true
echo bar
您还可以使用make-i…
忽略所有错误。Per:
-i,--忽略错误
忽略为重新生成文件而执行的命令中的所有错误
告诉make忽略该行返回的任何错误,唯一需要做的另一件事是分别运行这两个菜谱
example:
-somecommand && othercommand
echo 'hi'
怎么样badcommand | | true
?刚刚尝试过,仍然没有运行echo'hi'
问题是exit
比失败的命令更具侵入性,因为exit
实际上退出shell。如果Makefile确实包含exit
,则必须这样包装它:$(shell exit 1 | | true)
。对于任何其他失败的命令,不需要额外的包装。这会忽略所有错误,并且不允许我在代码中进行选择。