Catching error codes in a shell pipe

后端 未结 4 871
执笔经年
执笔经年 2020-11-27 13:14

I currently have a script that does something like

./a | ./b | ./c

I want to modify it so that if any of a, b or c exit with an error code

4条回答
  •  爱一瞬间的悲伤
    2020-11-27 13:41

    In bash you can use set -e and set -o pipefail at the beginning of your file. A subsequent command ./a | ./b | ./c will fail when any of the three scripts fails. The return code will be the return code of the first failed script.

    Note that pipefail isn't available in standard sh.

提交回复
热议问题