This script uses enough bash-isms (though none particularly fancy) that we should consider just declaring the shebang as /bin/bash.
If not, the bash-isms should be cleaned up.