bash – 如何在使用循环时使makefile退出并出错?

前端之家收集整理的这篇文章主要介绍了bash – 如何在使用循环时使makefile退出并出错?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我有以下bash命令:
for i in ./ x ; do ls $i ; done && echo OK

执行“ls ./”,然后执行“ls x”,失败(缺少x)并且不打印OK.

如果

for i in x ./ ; do ls $i ; done && echo OK

然后即使“ls x”失败,因为for循环中的最后一个语句成功,然后打印OK.在makefile中使用shell for循环时,这是一个问题:

x:
    for i in $(LIST) ; do \
        cmd $$i  ;\
    done

如果cmd的任何单独执行失败,如何使make失败?

使用break命令在命令失败时终止循环
x:
    for i in $(LIST) ; do \
        cmd $$i || break ;\
    done

但这并不会使makefile中止.您可以使用非零代码退出

x:
    for i in $(LIST) ; do \
        cmd $$i || exit 1 ;\
    done
原文链接:https://www.f2er.com/bash/384552.html

猜你在找的Bash相关文章