many script fixes

  * remove some bash-isms
  * remove some excessive non-posix-isms
  * bugs