From a7fb251dcba740cb4741e51bcdb9bb4b3972c6bc Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 30 Dec 2020 20:26:06 -0800 Subject: [PATCH] Created SC2284 (markdown) --- SC2284.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 SC2284.md diff --git a/SC2284.md b/SC2284.md new file mode 100644 index 0000000..74e9eb3 --- /dev/null +++ b/SC2284.md @@ -0,0 +1,35 @@ +## Use [ x = y ] to compare values (or quote '==' if literal). + +### Problematic code: + +```sh +if $var == value +then + echo "Match" +fi +``` + +### Correct code: + +```sh +if [ "$var" = value ] +then + echo "Match" +fi +``` + +### Rationale: + +ShellCheck found an unquoted `==` after a word. + +This was most likely supposed to be a comparison, so use square brackets as in the correct code. + +### Exceptions: + +If the `==` was supposed to be literal, you can quote it to make ShellCheck ignore it: + + grep '===' file.js + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file