From fa60b8a1799fdbde29ff3ea6ed64343e47cf3ff2 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 5 Jun 2021 18:52:08 -0700 Subject: [PATCH] Created SC2288 (markdown) --- SC2288.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 SC2288.md diff --git a/SC2288.md b/SC2288.md new file mode 100644 index 0000000..5ed331e --- /dev/null +++ b/SC2288.md @@ -0,0 +1,34 @@ +## This is interpreted as a command name ending with apostrophe. Double check syntax. + +(also applies to multiple other characters like `.,([{<>}])#"'`) + +### Problematic code: + +```sh +var=$("wget 'http://www.shellcheck.net/'") +echo Usage: $0 {start|stop|restart} +array=val1, val2, val3 + +``` + +### Correct code: + +```sh +var="$(wget 'http://www.shellcheck.net/')" +echo "Usage: $0 {start|stop|restart}" +array=(val1 val2 val3) +``` + +### Rationale: + +ShellCheck found a command name ending with a symbol, such as a comma, parenthesis, quote, or similar. This is almost always due to a syntax issue in the script. + +In the examples, bad quoting and invalid array syntax caused the shell to try to run commands ending in apostrophe, curly brace, and comma, respectively. + +### Exceptions: + +If you have a command that *does* end in a symbol, you can ignore this message. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file