3 ms·
This doesn't mention one of my favorite bash gotchas, which is using `set -e` with `pipefail` at all. Try this: set -euo pipefail yes | head That will
by peff 9y ago
This doesn't mention one of my favorite bash gotchas, which is using `set -e` with `pipefail` at all. Try this:
set -euo pipefail
yes | head
That will consistently exit because `yes` gets sigpipe and quits. Which is expected, but triggers a script exit. But more exciting is that something like:
generate_data | head
only _sometimes_ fail. It's a race that depends on whether generate_data is able to stuff all of its data into the pipe buffer before head calls close().
EDIT: I seemed to remember sharing this bug not too long ago, and indeed I did. pixelbeat responded with some interesting links: https://news.ycombinator.com/item?id=13940628 https://news.ycombinator.com/item?id=13940628
- deleted 9y ago[deleted]
- xyzzy_plugh 9y agoI don't know that this obviates the need to check PIPE_STATUS after the statement. As another poster mentioned, set -e and set -o pipefail are crutches and tell me the script it sloppy.