Fix several shellcheck warnings
- Check Check exit code directly [SC2181]
- Double quote to prevent globbing and word splitting. [SC2086]
- In POSIX sh, == in place of = is undefined. [SC3014]
- Declare and assign separately to avoid masking return values. [SC2155]
- In POSIX sh, echo flags are undefined. [SC3037]
- Use $(...) notation instead of legacy backticks .... [SC2006]
- $/${} is unnecessary on arithmetic variables. [SC2004]