From 487d7c69cd30c85032844c659fa7efabe7bec136 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 10 Nov 2013 11:19:41 -0800 Subject: [PATCH] Created SC1000: $ is not used specially and should therefore be escaped. (markdown) --- ...-specially-and-should-therefore-be-escaped..md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 SC1000:-$-is-not-used-specially-and-should-therefore-be-escaped..md diff --git a/SC1000:-$-is-not-used-specially-and-should-therefore-be-escaped..md b/SC1000:-$-is-not-used-specially-and-should-therefore-be-escaped..md new file mode 100644 index 0000000..525859e --- /dev/null +++ b/SC1000:-$-is-not-used-specially-and-should-therefore-be-escaped..md @@ -0,0 +1,15 @@ +### Rationale: +`$` is special in double quotes, but there are some cases where it's interpreted literally: + +1. Following a backslash: `echo "\$"` +2. In a context where the shell can't make sense of it, such as at the end of the string, (`"foo$"`) or before some constructs (`"$'foo'"`). + +To avoid relying on strange and shell specific behavior, any `$` intended to be literal should be escaped with a backslash. + +### Problematic sample code: + + echo "$" + +### Correct sample code: + + echo "\$"