unix shell, getting exit code with piped child

后端 未结 5 475
南旧
南旧 2021-01-18 07:21

Let\'s say I do this in a unix shell

$ some-script.sh | grep mytext

$ echo $?

this will give me the exit code of grep

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 08:10

    If you're using bash:

    PIPESTATUS
        An array variable (see Arrays) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command). 
    

提交回复
热议问题