Updated SC2088 (markdown)

koalaman
2015-06-14 10:24:20 -07:00
parent 40dfef8567
commit c0f1182cf7

@@ -1,4 +1,4 @@
## Note that ~ doesn't expand in quotes.
## Tilde does not expand in quotes. Use $HOME.
### Problematic code:
@@ -6,26 +6,13 @@
### Correct code:
rm ~/"Desktop/$filename"
rm "$HOME/Desktop/$filename"
### Rationale:
Tilde does not expand to the user's home directory when it's double quoted.
Tilde does not expand to the user's home directory when it's single or double quoted. Use double quotes and `$HOME` instead.
To expand it, the tilde, the optional username, and its following slash should be outside of the double quotes.
These strings expand:
~/file # Correct: tilde up to the slash is unquoted (everything is)
~/"$var" # Correct: tilde up to the slash is unquoted
~user/"hello world.txt" # Correct: tilde up to the slash is unquoted
These strings do not, leaving a literal tilde:
# Fails!
"~/file" # Wrong: tilde and slash are quoted when they shouldn't be.
~"/file" # Wrong: slash is quoted when it shouldn't be.
~user"/hello world.txt" # Wrong: slash is quoted when it shouldn't be.
Alternatively, the `~/` can be left unquoted, as in `rm ~/"Desktop/$filename"`.
### Exceptions