mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC3037 (markdown)
33
SC3037.md
Normal file
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!
|
Reference in New Issue
Block a user