Fix shebang line. This script is portable and does not require bash
which may not be installed on all systems.
don't rely on bash being present: use posix semantics when possible
merge miniscule tweaks to included shell scripts to allow software to run on freebsd (ymmv)  closes #2537