Updated SC2039 (markdown)

koalaman
2014-03-01 15:11:33 -08:00
parent 6666e556a4
commit d56da63b42

@@ -1,6 +1,9 @@
The $'...' construct is widely supported and in the process of being standardized, but it is not yet standard. Many shells do support it, including bash, ksh, zsh, and the busybox "sh" command. Since it is useful, POSIX has recently accepted $'...' (see http://austingroupbugs.net/view.php?id=249 ). However, POSIX-2013 does not include $'...', so a few shells do not yet support it. For now, be more specific about the shell, or use another construct (printf can often do the job).
## #!/bin/sh was specified, but _____ is not standard.
The $(...) construct strips trailing newlines. You can retain trailing newlines using this trick:
The shebang indicates that the script works with `/bin/sh`, but you are using non-standard features that may not be supported.
newline="$(printf '\nX')"
newline="${newline%X}
It may currently work for you, but it can or will fail on other OS, the same OS with different configurations or from different contexts (like initramfs/chroot), or different versions of the same OS, including future updates to your current system.
Either declare a specific shell like `#!/usr/bin/env bash` to make sure this shell is always used, or rewrite the script in a portable way.
For help with rewrites, the Ubuntu wiki has [a list of portability issues](https://wiki.ubuntu.com/DashAsBinSh) that broke people's `#!/bin/sh` scripts when Ubuntu switched from Bash to Dash. ShellCheck may not warn about all these issues.