SHELL中如何获得管道前面的命令的返回值

To know the exit status of the elements of a pipeline
cmd1 | cmd2 | cmd3
bash
The exit codes are provided in the PIPESTATUS special array.
cmd1 exit code is in ${PIPESTATUS[0]}, cmd3 exit code in
${PIPESTATUS[2]}, so that $? is always the same as
${PIPESTATUS: -1}.

随机文章:

发表评论