PROJET AUTOBLOG


Shaarli - Les discussions de Shaarli

Archivé

Site original : Shaarli - Les discussions de Shaarli du 23/07/2013

⇐ retour index

bc » Blog Archive » pipefail – testing pipeline exit codes

mardi 28 juillet 2015 à 11:31
@jeekajoo shaarlinks
"""
The problem

In bash, running test programs which indicate their pass or fail status via an exit code can be problematic when they are run as part of a pipeline in Linux, Mac OS X or Cygwin since the reported exit code of a pipeline is normally the exit code of the last program in the pipeline. If the test program is not the last program in the pipeline, then its exit code will be hidden by the exit code of the last program.
The solution

bash version 3 introduced an option which changes the exit code behavior of pipelines and reports the exit code of the pipeline as the exit code of the last program to return a non-zero exit code. So long as none of the programs following the test program report a non-zero exit code, the pipeline will report its exit code to be that of the test program. To enable this option, simply execute:

set -o pipefail

in the shell where the test program will execute.
"""
via https://github.com/progrium/bashstyle (Always use set -eo pipefail. Fail fast and be aware of exit codes. Use || true on programs that you intentionally let exit non-zero.)
(Permalink)