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

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...