https://mywiki.wooledge.org/BashFAQ
Also, always validate your scripts using shellcheck (https://www.shellcheck.net/)