Pure sh scripts should use /bin/sh as it's available on every platform.
When using bash-specific features, use env to find it, as bash can
be installed in different places according the OS.
Rebase of #610 and also move emscripten up much higher in the hierarchy to
ensure that it doesn't have too much of a ripple effect on other platforms.
This involved moving down a good number of definitions, but hopefully was done
with care to not break anything!