[arch-general] A good time to switch to dash as /bin/sh?

Drake Wilson drake at dasyatidae.net
Fri Sep 26 12:40:39 UTC 2014

On 26/09/14 07:30, Drake Wilson wrote:
> There is a _lot_ of "magic behavior" in bash.  Debian bug #762839 mentions
> how bash still imports shell functions from environment variables with magic
> names, even when called as sh.  The --posix option seems something of a joke.

Sorry, I mistyped; I meant magic values.

Incidentally this means that any environment variable of that form that
passes _through_ a bash instance to a subprocess will silently get mangled
in transit:

  % env 'foo=() { true; true; }' bash -c "dash -c 'printf %s\\\\n \"\$foo\"'"
  () {  true;

The function definition was reconstructed from some internal form
and reinjected into the environment, as you can see.  And of course during
the bash script itself it's not interpreted as a variable:

  % env 'foo=() { true; true; }' bash -c "printf '%s\\n' \"\${foo-oops}\""

How much more of this "hidden treasure" is there?

(There might be another approach involving convincing bash upstream to be
much stricter in --posix mode or when invoked as sh or something, but that
seems like a lot more work and less reliable.)

Aside: I'm not sure about the interpretation of checkbashisms re autotools
scripts (in particular libtool) because they do an awful lot of weird code
generation and shuffling to deal with multiple bogus shell implementations.

   ---> Drake Wilson

More information about the arch-general mailing list