Created SC2088 (markdown)

koalaman
2014-07-03 20:34:50 -07:00
parent abfe3c02a1
commit 7a2b4c9ea9

32
SC2088.md Normal file

@@ -0,0 +1,32 @@
## Note that ~ doesn't expand in quotes.
### Problematic code:
rm "~/Desktop/$filename"
### Correct code:
rm ~/"Desktop/$filename"
### Rationale:
Tilde does not expand to the user's home directory when it's double quoted.
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 (as is everything else)
~/"$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.
### Contraindications
If you don't want the tilde to be expanded, you can ignore this message.