Should now work equally well with bash (as on NixOS) and dash (on
various other distributions).
The only truly required change was on line 10: "function" is a
superfluous keyword that's not present in posix sh.
Change-Id: If917499b2e24c0d039e8c61208227b90c9fc5c0d