bash scripting across linux and solaris

Theodore Ruegsegger gruntly-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Fri Aug 28 16:11:09 EDT 2009


David wrote:
> On Fri, Aug 28, 2009 at 3:42 PM, Theodore Ruegsegger<gruntly-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
>>
>> Well, POSIX aside, if you call bash as sh, it clearly doesn't behave
>> as sh, as my little experiment with the array showed.
>
> With due respect, I don't think your experiment showed this.  You were
> attempting to use bash-specific syntax in sh.  If you were writing
> your scripts for portability, you presumably wouldn't be including
> bash-specific syntax, and bash doesn't ignore it's own semantics when
> called as sh.  If you removed all bash-specific syntax, I'm fairly
> certain (with some minor exceptions aside) that you would get the same
> result in both sh and bash.

Well, yeah, the point is that if bash allows non-sh syntax then it's
not "behaving as sh". If I am writing a script in sh for portability,
I'd really like the shell to warn me when I stray from pure sh.
Obviously, if I can write flawless sh, then I don't need any warning,
just as my flawless application code doesn't need any testing. Since I
use bash all day as my interactive shell, it's hardly to be expected
that I can write flawless sh without accidentally including some bash
syntax.

Ubuntu's /bin/sh, symlinked to dash, does "behave as sh" by
complaining when I use non-sh syntax.

Ted






More information about the Discuss mailing list