Fix some shell script errors

See the commit messages.