-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2088
Vidar Holen edited this page Jan 21, 2015
·
7 revisions
rm "~/Desktop/$filename"
rm ~/"Desktop/$filename"
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 (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.
If you don't want the tilde to be expanded, you can ignore this message.