mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2016 (markdown)
23
SC2016.md
Normal file
23
SC2016.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Expressions don't expand in single quotes, use double quotes for that.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
name=World
|
||||||
|
echo 'Hello $name'
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
name=World
|
||||||
|
echo "Hello $name"
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Single quotes prevent expansion of everything, including variables and command substitution.
|
||||||
|
|
||||||
|
If you want to use the values of variables and such, use double quotes instead.
|
||||||
|
|
||||||
|
### Contraindications
|
||||||
|
|
||||||
|
If you want `$stuff` to be a literal dollar sign followed by the characters "stuff", you can ignore this message.
|
||||||
|
|
||||||
|
ShellCheck tries to be smart about it, and won't warn when this is used with awk, perl and similar, but there are some inherent ambiguities like `'I have $1 in my wallet'`, which could be "one dollar" or "whatever's in the first parameter".
|
Reference in New Issue
Block a user