Created SC3037 (markdown)

Vidar Holen
2020-09-01 17:50:22 -07:00
parent 5c927dcdfe
commit a3084ae94f

33
SC3037.md Normal file

@@ -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!