Skip to content

Files

Latest commit

 

History

History
33 lines (21 loc) · 1.08 KB

SC2027.md

File metadata and controls

33 lines (21 loc) · 1.08 KB

Pattern: Malformed double quotes in shell script

Issue: -

Description

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.

Example of incorrect code:

echo "You enter "$HOSTNAME". You can smell the wumpus." >> /etc/issue

Example of correct code:

echo "You enter $HOSTNAME. You can smell the wumpus." >> /etc/issue

Further Reading