You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This ! is not on a condition and skips errexit. Add || exit 1 or make sure $? is checked.
Problematic code:
set -e
!false
rest
Correct code:
set -e
!false||exit 1
Rationale:
ShellCheck has found a command inverted with ! that may have no effect. In particular, it does not appear as a condition in an if statement or while loop, or as the final command in a script or function.
The most common reason for this is thinking that it'll trigger set -e aka errexit if a command succeeds, as in the example. This is not the case: ! will inhibit errexit both on success and failure of the inverted command.
Adding || exit will instead exit with failure when the command succeeds.
Exceptions:
ShellCheck will not detect cases where $? is implicitly or explicitly used to check the value afterwards: