From cc13ad3334f41505d4233588ada3de12627742f0 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 2 Nov 2022 20:20:59 -0700 Subject: [PATCH] Created SC2266 (markdown) --- SC2266.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 SC2266.md diff --git a/SC2266.md b/SC2266.md new file mode 100644 index 0000000..0dbec9b --- /dev/null +++ b/SC2266.md @@ -0,0 +1,30 @@ +## Use && for logical AND. Single & will background and return true. + +### Problematic code: + +```sh +if [ "$1" = "--verbose" ] | [ "$1" = "-v" ] +then + verbose=1 +fi +``` + +### Correct code: + +```sh +if [ "$1" = "--verbose" ] || [ "$1" = "-v" ] +then + verbose=1 +fi +``` +### Rationale: + +ShellCheck found a `test` command followed by a `|`. This was undoubtedly intended as a logical OR (`||`). + +### Exceptions: + +None + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file