From 399a3d5c80f03f6c056c94640783aed9637ed055 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 26 Jul 2021 19:17:55 -0700 Subject: [PATCH] Created SC2291 (markdown) --- SC2291.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 SC2291.md diff --git a/SC2291.md b/SC2291.md new file mode 100644 index 0000000..8edc52e --- /dev/null +++ b/SC2291.md @@ -0,0 +1,37 @@ +## Quote repeated spaces to avoid them collapsing into one. + +### Problematic code: + +```sh +echo Hello World +``` + +### Correct code: + +```sh +echo "Hello World" +``` + +### Rationale: + +ShellCheck found multiple unquoted spaces between words passed to `echo`. Due to the way arguments are interpreted and passed in the shell, these will collapse into a single space: + +``` +$ echo Hello World +Hello World +``` + +If you want to output multiple spaces, such as when creating a notice or banner, make sure the spaces are quoted, e.g. by adding (or extending) double quotes to include them: + +``` +$ echo "Hello World" +Hello World +``` + +### Exceptions: + +If you're aware of this behavior and didn't want multiple spaces to show up in the output, you can either remove the unnecessary spaces or [[ignore]] this issue. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file