GOTCHA in Ubuntu - broken shell
Fran Fadden
FranFadden+ghlug at pobox.com
Sat Sep 29 22:14:32 EDT 2007
Ben Scott wrote:
> On 9/29/07, Tyson Sawyer <tyson at j3.org> wrote:
>> If you say '/bin/sh' then you should speak '/bin/sh'.
>> If you are speaking '/bin/bash', then you should say, '/bin/bash'.
>
> It gets ugly in the other direction, too, BTW. Some people fall the
> habit of just putting "#!/bin/bash" at the top of every shell script
> they write, even those that do not use bash-specific features. If
> those shell scripts then go to a system which has *a* Bourne-like
> shell but not bash, they fail, because bash isn't available, even
> though another shell (which would have worked) is.
>
> And then we can get into extension which are present in multiple
> shells (say, bash and zsh) but not a basic, POSIX-compliant,
> Bourne-like shell. What do you do *then*?
It gets even worse still... Bash changes to "posix mode" when invoked
as /bin/sh. This means that there is at least a possibility that you've used
something in the gray area between bash's "posix" implementation and what
would work if you invoked the shell as "bash".
The problem is that the "standard" defines a range of acceptable implementations,
and any shell that falls in that range is a "posix" shell. I am not familiar
with dash, but I would be quite surprised if even dash implemented only that
part of the language that was *required* to be implemented in all posix shells,
with the most restrictive limits in all cases where posix specified a choice.
This means that even if you doctor all your scripts to work with both bash and dash,
there is no guarantee that the next implementation that comes along won't break
something else. This is why, from a user's point of view, I've always liked the
bash philosophy of including syntax from "historical" implementations so that users
don't *have* to retrain themselves.
The compiler folks faced this problem years ago, by providing an option (ok, *lots*
of options) to bitch when a program uses a construct that, while conforming to the
language definition, is not required to be present in every implementation of the
language. Maybe it is time for something like this in the shell too, or a "lint"
version of the shell, perhaps.
Meanwhile, I agree with the sentiment that "bash" (one version or another) should
be the "standard" shell on Linux distros and I am disappointed that Ubuntu (or *any*
major Linux distro) thinks so little of their users as to stick with this decision.
It ends up reflecting poorly on the Linux community as a whole.
Fran
More information about the gnhlug-discuss
mailing list