Skip to content

Files

Latest commit

 

History

History
28 lines (18 loc) · 745 Bytes

SC1135.md

File metadata and controls

28 lines (18 loc) · 745 Bytes

Pattern: Use of " to make $ literal

Issue: -

Description

The script appears to be closing a double quoted string for the sole purpose of making a dollar sign $ literal.

While this happens to work, the better solution is instead to escape it with a backslash. This allows the double quoted string to continue uninterrupted, thereby reducing the visual noise of stopping and starting quotes in the middle of a shell word.

Example of incorrect code:

echo "The apples are $""1 each"
eval "var=$"name

Example of correct code:

echo "The apples are \$1 each"
eval "var=\$name"
# or better yet: var="${!name}"

Further Reading