From 42570ff2e68e139cd99675c6a9bf072f76fd24c0 Mon Sep 17 00:00:00 2001 From: koalaman Date: Tue, 4 Jul 2017 11:59:25 -0700 Subject: [PATCH] Created SC1117 (markdown) --- SC1117.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 SC1117.md diff --git a/SC1117.md b/SC1117.md new file mode 100644 index 0000000..8a43098 --- /dev/null +++ b/SC1117.md @@ -0,0 +1,31 @@ +## Backslash is literal in `"\n"`. Prefer explicit escaping: `"\\n"`. + +### Problematic code: + +```sh +printf "%s\n" "Hello" +``` + +### Correct code: + +```sh +printf "%s\\n" "Hello" +``` + +or alternatively, with single quotes: + +```sh +printf '%s\n' "Hello" +``` + +### Rationale: + +In a double quoted string, you have escaped a character that has no special behavior when escaped. Instead, it's invoking the fallback behavior of being interpreted literally. + +Instead of relying on this implicit fallback, you should escape the backslash explicitly. This makes it clear that it's meant to be passed as a literal backslash in the string parameter. + +### Exceptions: + +None. This is a stylistic issue which can be [[ignore]]d. + +Before you do -- can you name the 4 characters that *are* special when escaped in double quotes? \ No newline at end of file