From b616d51abb0b2cf0d1b76e753da9b195e18929c2 Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 7 May 2014 21:45:48 -0700 Subject: [PATCH] Created SC2140 (markdown) --- SC2140.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 SC2140.md diff --git a/SC2140.md b/SC2140.md new file mode 100644 index 0000000..2a94795 --- /dev/null +++ b/SC2140.md @@ -0,0 +1,24 @@ +## The double quotes around this do nothing. Remove or escape them. + +### Problematic code: + + echo "" > file.html + +### Correct code: + + echo "" > file.html + +### Rationale: + +This warning triggers when an unquoted literal string is found between two double quoted strings. In many such cases (like the example) the quotes were supposed to be literal, and should be escaped. Without escaping, the quotes are simply removed, resulting in `src=foo.png` instead of `src="foo.png"`. + +In other cases, like `echo "$USER"@"$HOSTNAME"`, they are merely pointless and can be removed for improved readability: `echo "$USER@HOSTNAME"`. + +Note that in some of these cases, curly brackets would have to be added: `"$lastname"_"$firstname"` would be `"${lastname}_$firstname"`, otherwise it'd look for a variable named `$lastname_`. + +It's common to quote individual parts of a path: `"$dir"/"$file"`. This is pointless and hard to read, but rarely indicates a bug. ShellCheck doesn't warn in this particular case. + + +### Contraindications + +If you know that the quotes are ineffectual but you prefer it stylistically, you can ignore this message. \ No newline at end of file