According to this post:
The exit status of the
ifcommand shall be the exit status of thethenorelsecompound-list that was executed, or zero, if none was executed.
This leads to a bug in my bash script where:
- I have
set -euo pipefailset in the script and expect it to stop executing if any errors arise - I have an if statement with a condition that errors, but execution continues because -e doesn't care about the condition in if statements
Specifically, I have an if function1; then and I want to shield from the case where function1 doesn't exist.
The scenario is that someone modifies function1, it no longer exists, but the script runs fine and the user doesn't realize that the script failed.
This is meant to be for every if statement in a bash file, so it's not a matter of making sure function1 exists, I'm looking for a blanket solution for a file, like set -euo pipefail that requires as little refactoring as possible.
I've looked in the set documentation, and nothing seems to be suitable there.
Summary:
function1 does not exist
run if function1; then ...
Expected:
script exits
Actual:
whatever.sh: line ##: function1: command not found
script continues
set -eoperates. If the error occurs within a logical test (if,&&, or||), it does not trigger exit.