为什么这个 fish while 循环在单次迭代后终止?

Why does this fish while loop terminate after a single iteration?

这是一个 fish 函数,用于升级项目的 JavaScript 包。奇怪的是,它在退出状态为 0 的单次迭代后终止。为什么?

function yarn-upgrade-all --description "Upgrade JavaScript packages"
    yarn outdated | sed '1,/^Package/d;/^Done/d' | awk '{print , }' | while read -l PACKAGE VERSION
        echo
        set_color brwhite
        echo -n "==>"
        set_color yellow
        echo -n " "$PACKAGE
        set_color brblue
        echo -n " "$VERSION
        set_color brwhite
        echo -n " <=="
        set_color normal
        echo
        echo

        yarn upgrade --latest $PACKAGE
        and yarn run test
        and yarn run build
        and git commit -am "Upgrade to "$PACKAGE" "$VERSION
        or begin
            set_color red
            echo "last command exited with status $status" >&2
            set_color normal
            return 1
        end
    end
end

另一方面,第二个函数只包含一个存根体,遍历通过管道进入循环的所有包。

function yarn-upgrade-all-debug --description "Upgrade JavaScript packages"
    yarn outdated | sed '1,/^Package/d;/^Done/d' | awk '{print , }' | while read -l PACKAGE VERSION
        echo $PACKAGE $VERSION
    end
end

fish --version

fish, version 3.0.2

您是 运行 fish 3.0.0,从 while 中点击 https://github.com/fish-shell/fish-shell/issues/5513 - return 实际上并没有正确设置状态。

但是,return 仍然会导致它终止 while 循环。

升级到 3.0.2。

循环在单次迭代后终止,因为循环体中的 yarn run 调用耗尽了标准输入的其余部分。 (感谢 。)

一个可能的解决方法是将这些命令的标准输入重定向到 /dev/null

        and yarn run test < /dev/null
        and yarn run build < /dev/null

罪魁祸首是 npm-run-all 包中的 run-s,它被两个 yarn run 命令调用。

https://github.com/mysticatea/npm-run-all/issues/166