3 ms·
https://github.com/anordal/shellharden/blob/master/how_to_do_things_safely_in_bash.md#how-to-use-errexit https://github.com/anordal/shellharden/blob/master/how_
by mcc1ane 2mo ago
https://github.com/anordal/shellharden/blob/master/how_to_do_things_safely_in_bash.md#how-to-use-errexit https://github.com/anordal/shellharden/blob/master/how_to_do...
- mananaysiempre 2mo agoTL;DR: The old-school empty branch preserves $?, while logical negation doesn’t. Sure I guess, but this is not always relevant.
- tzot 2mo agoDo you have a real-world example where we would like to preserve `$?` after the `if` (which `if` specifically branches on the result code of the command it tests)? Where we want to use the actual return code that the `if` did not handle itself. I am asking because I have never needed preserving the `$?` outside of an `if`, nor have I ever seen this in somebody else's scripts, and I'm curious.