Reading Exit Status Across Several Commands

A pipeline includes the outcomes of separate commands. The shell's reported pipeline status depends on its rules and settings.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace an incomplete report
  2. Test the actual shell mode
  3. Trace separate statuses when a consumer accepts partial work
  4. Check which failures the workflow must surface

Trace an incomplete report

An exporter can fail halfway while a consumer still finishes parsing earlier valid rows. A downstream success status does not describe the earlier failure by itself. Build exit status gives a similar publication risk.

Test the actual shell mode

Simulate the early failure with a controlled fixture. Verify that the enclosing script treats the pipeline as incomplete and does not publish partial output. See file replacement after success.[1]

Trace separate statuses when a consumer accepts partial work

A first step fails after writing two of three rows. A second step counts two and exits successfully. In shells or modes that use the last status for the pipeline, the aggregate result can be success despite incomplete input. See build pipeline exit status.

Producer: writes two rows, exits 1
Counter: prints 2, exits 0
Pipeline configured to report only last step: exit 0
Validate exact shell behavior for your contract

Check which failures the workflow must surface

A consumer intentionally stopping early can close the pipe before upstream completion. That may be expected. Test this separately from unexpected malformed input or I/O failure.

References

  1. The Open Group, POSIX Shell Command Language ↩