Fix bashisms, make script runnable with POSIX shell (for example, on FreeBSD)