4 ms·
I often add a fail-unless function: fail-unless() { local result "$@" result=$? if ((result != 0)); then echo >2&1 "Failed
by halostatue 3y ago
I often add a fail-unless function:
fail-unless() {
local result
"$@"
result=$?
if ((result != 0)); then
echo >2&1 "Failed ${result} with command '$*'."
exit ${result}
fi
}
That way, I know exactly what failed in the script.
- sureglymop 3y agoYou do e.g. `fail-unless somecommand`. The result (exit/return code) is captured in the function and based on that, the function logs and exits or not.
- ykonstant 3y agoYou probably meant to reply to BeefySwain, right?
- BeefySwain 3y agoHow does this work exactly? What calls that function and when?