4 ms·
Yes. Always chain sequential commands with &&. Always. This style is pretty prevalent when writing test cases in shell (or just shell scripts in general), e.g
by davvid 12y ago
Yes. Always chain sequential commands with &&. Always.
This style is pretty prevalent when writing test cases in shell (or just shell scripts in general), e.g. when using something like sharness[1].
[1] https://github.com/mlafeldt/sharness https://github.com/mlafeldt/sharness
- stingraycharles 12y agoWhen writing test cases in shell, you generally just implement a die() function and execute all commands `foo || die "bar"`
- nitrogen 12y agoIf you don't need to specify a custom message, you could also use "set -e" to die automatically on command failure and use "trap ... EXIT" to display some kind of failure message.
- pimlottc 12y ago"bash -e" has much the same effect: it basically exits on the first failed command, with considerations for pipelines, conditionals and the like. http://www.gnu.org/software/bash/manual/bashref.html#index-set http://www.gnu.org/software/bash/manual/bashref.html#index-s...
- pflanze 12y agoNote this recent discussion about bash -e, including my post that "the disappointment with set -e is that it does not work everywhere". https://news.ycombinator.com/item?id=8054440 https://news.ycombinator.com/item?id=8054440
- blueskin_ 12y agoIt's nice to have, but I wouldn't rely on it to save me - it's no replacement for checking return codes properly.
- deleted 12y ago[deleted]