FreeBSD portability fixes

Small changes allowing the script to be run on FreeBSD.