Re:fork() can fail
by staunch on Wednesday August 20, 2014 @04:53PM
(#8204555)
[ Parent
| on HN ]
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].
"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-s...
Note this recent discussion about bash -e, including my post that "the disappointment with set -e is that it does not work everywhere".
It's nice to have, but I wouldn't rely on it to save me - it's no replacement for checking return codes properly.
Certainly, but it's a good habit to get into, like ``use strict`` in Perl.
"Perl and line noise are distinguishable. Properly written perl starts with 'use strict'; line noise rarely does."
Re:fork() can fail
by stingraycharles on Thursday August 21, 2014 @12:38AM
(#8205953)
When writing test cases in shell, you generally just implement a die() function and execute all commands `foo || die "bar"`
If 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.