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
The error message of shellcheck needs to be changes as well. From
This ! is not on a condition and skips errexit. Use && exit 1 instead, or make sure $? is checked.
to something like:
This ! is not on a condition and skips errexit. Add || exit 1 or make sure $? is checked.
bdrung
changed the title
The "Correct code" for SC2251 can result in a wrong exit code
The "Use && exit 1" for SC2251 can result in a wrong exit code
Jan 13, 2025
The "Correct code" from https://github.com/koalaman/shellcheck/wiki/SC2251 can result in a wrong exit code. I stumbled over this issue while working on https://salsa.debian.org/kernel-team/initramfs-tools/-/merge_requests/144
Here's a snippet that shows the problem:
Shellcheck will correctly complain about SC2251, but this script works correctly (as long as the
!
check is the last command):Here's what shellcheck recommends:
https://github.com/koalaman/shellcheck/wiki/SC2251 recommends to change the code to:
This causes the script to always exit with error code 1:
Here's what I suggest:
Adding
|| exit 1
would work for this case and probably for all other cases:Then the exit code will be 0 again for the "successful" case:
The text was updated successfully, but these errors were encountered: