From 7a2b4c9ea996c235459c53ccee57cc4aecee9724 Mon Sep 17 00:00:00 2001 From: koalaman Date: Thu, 3 Jul 2014 20:34:50 -0700 Subject: [PATCH] Created SC2088 (markdown) --- SC2088.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 SC2088.md diff --git a/SC2088.md b/SC2088.md new file mode 100644 index 0000000..e308d73 --- /dev/null +++ b/SC2088.md @@ -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. \ No newline at end of file