Fix build on FreeBSD.

FreeBSD's shell could not accept "if [[ ]];" syntax,

I make some change to make it compatible with sh/bash.

please help to review it. thanks.