Another useful flag is -x, which enables tracing (Bash will print each command before executing it).
You can disable it again with set +x (same goes for +e, +u and afaik +o pipefail)
Also, please use shellcheck - https://www.shellcheck.net/
EDIT: Also, please don't modify scripts while they are running.