From d777f3877f615db2ee726b243d2aaa9ae9a54f39 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 30 Dec 2020 20:05:52 -0800 Subject: [PATCH] Created SC2276 (markdown) --- SC2276.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 SC2276.md diff --git a/SC2276.md b/SC2276.md new file mode 100644 index 0000000..ebdc4a8 --- /dev/null +++ b/SC2276.md @@ -0,0 +1,37 @@ +## This is interpreted as a command name containing '='. Bad assignment or comparison? + +### Problematic code: + +```sh +"$var"=42 +if "$var"=42 +then + true +fi +``` + +### Correct code: + +```sh +var=42 +if [ "$var" = 42 ] +then + true +fi +``` + +### Rationale: + +ShellCheck found a command name containing an unquoted equals sign `=`. This was likely intended as either a comparison or an assignment. + +To compare two values, use e.g. `[ "$var" = "42" ]` + +To assign a value, use e.g. `var="42"` + +### Exceptions: + +None, though you can quote the `=` to make ShellCheck ignore it: `"$var=42"`. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file