鱼类管道状况

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

在鱼中:

if false | true | true
  echo "Fish thinks OK because of last status"
else
  # But I...
  echo "Need the entire pipeline to be true"
end

Bash 有 $PIPESTATUS。 如何测试 Fish 中管道的完整性?

为了澄清... 我在示例管道中使用 true 和 false 作为示例 最后一个组件成功的管道。 它并不意味着是一个布尔语句。 通常,如果管道的任何组件发生故障, 人们会认为管道已经失败。

shell status pipeline fish
2个回答
2
投票

目前不可能(除了通过

set var (echo $initialinput | firstcommand); and set var (echo $var | secondcommand); and
...j

手动构建管道的丑陋解决方法)

这被追踪为 fish bug #2039


0
投票

这个问题真的很老了,对于现代鱼来说没有准确的答案。 faho 提到的功能请求 (#2039) 已于 2019 年实现。您现在可以像其他 shell 一样检查管道状态:

true | false | true | true
if string match -qr '[^0]' $pipestatus
    echo "handle error"
end

如果您对

test
运行多个
$pipestatus
调用,请记住它是易失性的,需要保存到自己的变量中,这样您就不会在多次调用
test
时对其进行核攻击:

true | false
set --local last_pipestatus $pipestatus
if test $last_pipestatus[1] -ne 0 || test $last_pipestatus[2] -ne 0
    echo "handle error"
end
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.