From 37bb0d0ec7dd87c64714143e07d2a9d7d76112e8 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 16 May 2025 18:24:23 -0700 Subject: [PATCH] Created SC2334 (markdown) --- SC2334.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 SC2334.md diff --git a/SC2334.md b/SC2334.md new file mode 100644 index 0000000..90bf738 --- /dev/null +++ b/SC2334.md @@ -0,0 +1,34 @@ +## You probably wanted || here, otherwise it's always false. + +### Problematic code: + +```sh +if (( ret == 137 && ret == 143 )) +then + echo "Process killed by SIGTERM/SIGKILL" +fi +``` + +### Correct code: + +```sh +if (( ret == 137 || ret == 143 )) +then + echo "Process killed by SIGTERM/SIGKILL" +fi +``` +### Rationale: + +The problematic condition will never trigger because of a logic error. + +In English one think say "I want to check for the numbers `137` and `143`", but the test ends up checking that the number is both `137` and `143` at the same time, which it can't be (if the number is 137, it necessarily won't be 143, and vice versa). + +The correct check is "if the number is `137` or if the number is `143`", which will be true if the value is either 137 or 143. + +### Exceptions: + +None + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file