1 TL;DR
The return status of a pipeline is the exit status of the last command unless the pipefail option is enabled.
$ true | false | true | false
[smstong@cf-31 ~]$ echo $?
1
2 exit code of each command
Sometimes, you may want to know the exit code of other commands besides the last one.
The exit codes of each command in the pipeline are saved in an array named PIPESTATUS.
$ true | false | true | false
$ echo ${PIPESTATUS[@]}
0 1 0 1
3 background pipeline always exit with 0
When a pipeline is running as a background job, its exit code is always 0.
$ true | false | true | false &
[1] 3607306
[smstong@cf-31 ~]$ echo $?
0
No comments:
Post a Comment