Fix and support sh (not bash) script standard.

* sh is not support `$()` syntax. replacing to ``.
* `set -e` is good practice on shell scripting.
* shell function have to be defined before using it.
I replaced these in 5a0fb14edcb7a470adf40454af4346a7da2f28b6