From 58e4155f9740d0ad298677da59fc928c6e200cf9 Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 5 Jul 2017 09:59:09 -0700 Subject: [PATCH] Updated SC1001 (markdown) --- SC1001.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/SC1001.md b/SC1001.md index 1034cb2..d50f7e8 100644 --- a/SC1001.md +++ b/SC1001.md @@ -1,27 +1,37 @@ -## This `\c` will be a regular 'c' in this context. +## This `\o` will be a regular 'o' in this context. ### Problematic code: ```sh +# Want literal backslash echo Yay \o/ -\git status # Non-POSIX way to suppress aliases + +# Want linefeed +greeting=Hello\nWorld + +# Want other characters +carriagereturn=\r ``` ### Correct code: ```sh echo 'Yay \o/' -command git status + +greeting='Hello +World' + +carriagereturn=$(printf '\r') ``` ### Rationale: -Escaping something that doesn't need escaping sometimes indicates a bug. +You have escaped something that has no special meaning when escaped. The backslash will be simply be ignored. -If the backslash was supposed to be literal, single quote it. +If the backslash was supposed to be literal, single quote or escape it. -If the purpose is to run an external command rather than an alias, prefer `command`. +If you wanted it to expand to something, rewrite the expression. For linefeeds (`\n`), put them literally in quotes. For other characters, use POSIX `printf` or bash/ksh `$'...'`. ### Exceptions -If you have an alias and a function (as opposed to an external command), you can either ignore this message or use `"name"` instead of `\name` to quiet ShellCheck. \ No newline at end of file +None. ShellCheck (as of 2017-07-03, commit 31bb02d6) will not warn when the first letter of a command is unnecessarily escaped, as this is frequently used to suppress aliases interactively. \ No newline at end of file