From d56da63b423bc3d01bde614f30a0eafc89e492bd Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 1 Mar 2014 15:11:33 -0800 Subject: [PATCH] Updated SC2039 (markdown) --- SC2039.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SC2039.md b/SC2039.md index 2e3bac0..a7d1c35 100644 --- a/SC2039.md +++ b/SC2039.md @@ -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. \ No newline at end of file