4 ms·
`-o pipefail` is not without its gotchas bash -eo pipefail -c "cat /etc/services | head -1; echo never got here"
by loevborg 6y ago
`-o pipefail` is not without its gotchas
bash -eo pipefail -c "cat /etc/services | head -1; echo never got here"
- aidenn0 6y agoI hate pipefail. I find set -e also has some gotchas. '|| die' added to the end of each line is uglier but more obvious in many cases.
- deleted 6y ago[deleted]
- stonewareslord 6y agoWhat is the gotcha here? You’re telling it to pipefail and exit on fail, so it exits.
- tux1968 6y agoThe gotcha is perhaps failing to recognize that cat will actually fail in this simple pipeline because its output is truncated "unexpectedly" by head exiting after completing its job properly. (Maybe you could argue that head should be a good citizen and read its input to completion) Where this will work as expected: bash -eo pipefail -c "head < /etc/services -1|cat ; echo got here"
- gray_-_wolf 6y agoBut head is a being a good citizen by doing only what it needs to do and not anything else. Otherwise things like `grep X <5GBfile | head -n1` would process the whole file and not just until the first match.