2

I am on zsh 5.8 (arm-apple-darwin20.2.0). Unlike the way PIPESTATUS in bash is available to read during the next shell prompt, pipestatus of pipe in zsh seems to disappear in the following prompt.

❯ true | false | true ; echo $pipestatus
0 1 0

❯ true | false | true
❯ echo $pipestatus
0

This behavior is unlike that suggested in the answer here, and the zsh document does not mention anything regarding this.

2
  • 3
    Maybe something in your prompt or promp commands uses pipes?
    – muru
    Commented Oct 15, 2021 at 7:40
  • @muru Ok sure, something in zdharma/zinit is doing it... if i add these commands to a script, it prints correctly. Thanks!
    – codepoet
    Commented Oct 15, 2021 at 7:44

1 Answer 1

2

As muru wrote in a comment, something is using a pipe and thus overwriting pipestatus, probably in prompt-related automation. The most likely culprit is a hook function such as precmd and preexec¹.

Bash saves $?, PIPESTATUS and a bunch of other things around traps and PROMPT_COMMAND (save_parser_state). Zsh saves $? in a number of circumstances (in the source, look for places that save lastval) including around expanding the prompt (promptexpand) and running hooks such as precmd and preexec (callhookfunc calls doshfunc with noreturnval=1), but it never saves pipestatus.

¹ Code in the prompt can also set variables if prompt_subst is set, but a pipe there would be in a subshell and would not overwrite the original shell's pipestatus.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .