Convert perl script to bash

For a better compatibility
Merge pull request #507 from googley/master

Convert perl script to bash