From a3084ae94fe2dcb65cc06e50902dcd82639904a1 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Tue, 1 Sep 2020 17:50:22 -0700 Subject: [PATCH] Created SC3037 (markdown) --- SC3037.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 SC3037.md diff --git a/SC3037.md b/SC3037.md new file mode 100644 index 0000000..9881f9a --- /dev/null +++ b/SC3037.md @@ -0,0 +1,33 @@ +## In POSIX sh, echo flags are undefined. + +### Problematic code: + +```sh +#!/bin/sh +echo -ne 'Foo:\tBar' +``` + +### Correct code: + +Rewrite in terms of the more robust and standardized `printf`: + +```sh +#!/bin/sh +printf 'Foo:\tBar' +``` + +### Rationale: + +`echo` has historically behaved differently on different systems. Use `printf` instead to ensure compatibility between shells. + +### Exceptions: + +If you only intend to target shells that supports this feature, you can change +the shebang to a shell that guarantees support, or [[ignore]] this warning. + +You can use `# shellcheck disable=SC3000-SC4000` to ignore all such compatibility +warnings. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!