如何在 Bash 中打破循环命令,特别是在 make Recipe 中

问题描述 投票:0回答:1

我有这个制作食谱。

run_pipelines:
    @[ "${filter}" ] || ( filter="."; ) && \
    filter=$$(echo "$$filter" | sed -e 's/\./.*/g') && echo $${filter}"<3" && \
    echo "\033[1;34m#######Running Pipelines for $${filter}#######\033[0m" && \
    find v2/services -type f -regex ".*$${filter}.*.jsonnet" -print0 | \
    xargs -r -0 -I {} bash -c 'echo -e "\033[1;32mjsonnet {} \033[0m"; jsonnet {} || exit $$?'
.PHONY: run_pipelines

它循环遍历所有 jsonnet 文件并运行 jsonnet 命令。 我希望它失败并在单个 jsonnet 命令失败后立即停止。

我尝试了一些方法,但没有任何效果。

bash makefile
1个回答
0
投票

如果您的

find
-quit
,则不要通过管道输入
xargs
bash

    ...
    find v2/services -type f -regex ".*$${filter}.*.jsonnet" -print0 | \
    xargs -r -0 -I {} bash -c 'echo -e "\033[1;32mjsonnet {} \033[0m"; jsonnet {} || exit $$?'
    ...

只需使用

find
-exec
选项即可直接测试其返回:

    ...
    find v2/services -type f -regex ".*$${filter}.*.jsonnet" \
        -printf '\033[1;32mjsonnet %p \033[0m" \
        \( -exec jsonnet {} \; -o quit \)
    ...
© www.soinside.com 2019 - 2024. All rights reserved.