From 0298133f54b59b5076593e21f6a76773e717f965 Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 7 May 2014 21:07:35 -0700 Subject: [PATCH] Created SC2027 (markdown) --- SC2027.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC2027.md diff --git a/SC2027.md b/SC2027.md new file mode 100644 index 0000000..cfac0e3 --- /dev/null +++ b/SC2027.md @@ -0,0 +1,25 @@ +## The surrounding quotes actually unquote this. Remove or escape them. + +### Problematic code: + + echo "You enter "$HOSTNAME". You can smell the wumpus." >> /etc/issue + +### Correct code: + + echo "You enter $HOSTNAME. You can smell the wumpus." >> /etc/issue + +### Rationale: + +Always quoting variables and command expansions is good practice, but blindly putting quotes left and right of them is not. + +In this case, ShellCheck has noticed that the quotes around the expansion are unquoting it, because the left quote is terminating an existing double quoted string, while the right quote starts a new one: + + echo "You enter "$HOSTNAME". You can smell the wumpus." + |----------| |---------------------------| + Quoted No quotes Quoted + +If the quotes were supposed to be literal, they should be escaped. If the quotes were supposed to quote an expansion (as in the example), they should be removed because this is already a double quoted string. + +### Contraindications + +None. \ No newline at end of file