sh scripts needed some lovin'

I've taken the liberty of cleaning up your sh scripts. They should all still be fully compatible with bash and zsh.

In the process, I've done a number of things:
* fixed some quoting inconsistencies and added double-quotes around all parameter expansions
* fixed some potentially troublesome function definitions
* saved quite a few subprocesses and forks wherever I could
* adhered to variable naming conventions for non-environment variables
* switched most echo calls to printf
* change exports to the POSIX style; assigning variables during a call to export is discouraged

All changes are easily visible in the diffs, and my commit messages were accurate and sufficiently detailed (though i think i got one or two of them mixed up, oops). No changes should require new tests, because I have taken care to introduce exact equivalence in functionality, and most changes are purely cosmetic or syntactical.

My one remaining complaint is this: your tests use 'funcname() {' for function definitions, but your contribution guidelines explicitly state that we should use the `function' keyword.

I would submit that the preferred style be changed to 'funcname() {' as per this [guideline](http://mywiki.wooledge.org/BashPitfalls#function_foo.28.29)