Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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
Bash 即使其中的一个操作失败,也要继续执行make命令_Bash_Shell_Makefile - Fatal编程技术网

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

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

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

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

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)
。对于任何其他失败的命令,不需要额外的包装。这会忽略所有错误,并且不允许我在代码中进行选择。