03dc8cd808
pipefail might be ideal here but not sure how wide the support is yet considering this may run on plain sh.