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!