To help you with debugging your BASH scripts, you can use set this option which will print command traces before executing command
# set -o xtrace
Try it and you will love it.
For further notes, do read the
- Debugging Bash scripts by Bash Guide for Beginners