3 ms·
In the Linux world, Debian/Ubuntu made a fateful decision to deploy the Almquist shell as /bin/sh. They left /bin/bash as the interactive shell, but anything as
by chasil 5y ago
In the Linux world, Debian/Ubuntu made a fateful decision to deploy the Almquist shell as /bin/sh. They left /bin/bash as the interactive shell, but anything assuming the presence of a "bashism" in /bin/sh suddenly broke. Also inconvenient is that scripts calling /bin/bash behave differently from bash running as /bin/sh (alias expansion is disabled in the former, and likely other POSIX violations that I have not seen).
Almquist allows the local keyword, in violation of the POSIX standard. The wiki says that this is the only extension.
The original article's motivation is for Almquist running under FreeBSD. Almquist is also used in Busybox with a few bash-compatibilty adjustments. However, there are other pure POSIX shells out there, and it is worth adhering to the standard.
Almquist is also much faster than bash, so speed joins compatibility as factors for standard adherence.
- spicybright 5y agoThis decision has always confused me. Does debian use a bunch of scripts that rely specifically on sh or something? Is the speed hit that bad using bash?
- chasil 5y agoThe Debian/Ubuntu decision to forbid non-POSIX shell features was not likely made for scripts that "rely" on strict POSIX conformance, as most shells implement it (bash has a POSIXLY_CORRECT mode). I think that portability and speed were greater concerns. There were many support tickets asking for bash to be restored as /bin/sh. https://bugs.launchpad.net/ubuntu/+source/dash/+bug/141481 https://bugs.launchpad.net/ubuntu/+source/dash/+bug/141481
- kazinator 5y ago> in violation of the POSIX standard. local is not in violation of the POSIX standard; it's listed there precisely because it's known extension. The behavior is unspecified; the shells are free to specify it.
- chasil 5y agoWell then, by all means, feel free to use [[ and function. What you write will not run in Almquist or other POSIX shells, but don't let that stop you... until it does. For the practical concern of portability, none of these are compliant, no matter our protests otherwise. They fail. "The following words may be recognized as reserved words on some implementations (when none of the characters are quoted), causing unspecified results: [[, ]], function, select."