From 98a19c0fdc9e1efb492a9ff959ba108a3d079fd8 Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Sat, 27 Feb 2016 18:57:19 -0500 Subject: [PATCH] Created SC1003 (markdown) --- SC1003.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 SC1003.md diff --git a/SC1003.md b/SC1003.md new file mode 100644 index 0000000..ad6f0d8 --- /dev/null +++ b/SC1003.md @@ -0,0 +1,24 @@ +Are you trying to escape that single quote? `echo 'You'\''re doing it wrong'`. +============================================================================== + +### Problematic code: + +```sh +echo 'You\'re doing it wrong' # unclosed single quote +``` + +### Correct code: + +```sh +echo 'You'\''re doing it wrong' +echo $'You\'re doing it wrong' # ksh/bash/zsh "c-style" quote +``` + +### Rationale + +In POSIX shell, the shell cares about nothing but another single quote to terminate the quoted segment. Not even backslashes are interpreted. + +[POSIX.1 Shell Command Language ยง 2.2.2 Single Quotes](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_02_02): + +> Enclosing characters in single-quotes ( `''` ) shall preserve the literal value of each character within the single-quotes. A single-quote cannot occur within single-quotes. +