POSIX compliant - usable on Solaris systems, without bash.

Script now works even without GNU Bash.