switch Bash script to better error reporting