Some bizarre fixes that make this script work properly under both BSD and GNU environments.