Re:Why doesn't Bash's `set -e` do what I expected?
by dataflow on Thursday October 06, 2022 @11:46PM
(#33117200)
It's the best kind of correct, yes.
[ Parent
| on HN ]
Re:Why doesn't Bash's `set -e` do what I expected?
by nikau on Thursday October 06, 2022 @11:51PM
(#33117223)
It's a pretty bizarre use case, why would you need the second if statement, you already are in logic based on the return code
I can't think of an example of the if statement being confusing that isn't relying on $?
Re:Why doesn't Bash's `set -e` do what I expected?
by dataflow on Thursday October 06, 2022 @11:56PM
(#33117248)
error=0
if ! some_command; then error=$?; bar; fi
echo "blah"
return $error
Re:Why doesn't Bash's `set -e` do what I expected?
by nikau on Friday October 07, 2022 @12:24AM
(#33117423)
Yep that's a valid scenario, if you need more granularity than just fail or success then you will have to use a different method, e.g.
Status=0
Somecommand || status=$?
Then do logic based on status