即使其中一个操作失败,也继续执行 make 命令



我正在寻找一种在错误失败时继续执行make命令的方法。

我需要一种包装命令的方法,这样它就不会响应退出代码 1。

test:
    exit 1 ;
    echo 'hi' ;

我需要一种方法来包装这样的东西:

example:
   somecommand && othercommand ;
   echo 'hi' ;

somecommand可以退出并显示1(错误)并且不运行othercommand0运行othercommand

这应该可以:

test:
    commandThatMayFail && otherCommand || true
    echo hi

你可以这样尝试:

test:
    rm fileDoesNotExist && echo foo || true
    echo bar

您还可以使用 make -i ... 忽略所有错误。 根据手册页:

-i, --忽略错误

忽略为重新生成文件而执行的命令中的所有错误。

在食谱前面加上-告诉 make 忽略该行返回的任何错误,您唯一需要做的就是分别运行这两个配方。

example:
   -somecommand && othercommand
   echo 'hi'

最新更新