Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

$pipestatus and shell functions



Hello,

I'm somewhat confused by the behaviour of the $pipestatus variable:

$ true | true ; echo $pipestatus
0 0
$ false | true ; echo $pipestatus
1 0
$ true | false ; echo $pipestatus
0 1
$ false | false ; echo $pipestatus
0 0
$ foo() { true }
$ true | foo ; echo $pipestatus
0 0
$ false | foo ; echo $pipestatus
1 0

So far, everything is fine for me, but then:

$ foo() { false | true }
$ true | foo ; echo $pipestatus
1 0
$ foo() { false | false }
$ true | foo ; echo $pipestatus
1 1
$ foo() { true | true | true }
$ false | foo ; echo $pipestatus
0 0 0

So $pipestatus is defeated by multiple pipelining…

Is this by design? If so, is there some not-so-complicated workaround
to get the exit code of process A in “ A | B ” for any B (ie. even if
B is itself a shell function with a pipe)?

Thanks in advance, best regards,

-- 
Jérémie



Messages sorted by: Reverse Date, Date, Thread, Author