It is sometimes good to have a lil relaxation. For some, it's the piano, painting or sports ... And for others, it's writing Shell scripts.
But unfortunately, not everyone is born with the infused science, and it is common to make some little mistakes, especially if you have the habit of copying and pasting things from forums.
Fortunately, there is ShellCheck, a Linux / Unix application that allows you to control the content of your bash scripts, to tell you the corrections or improvements to make, and so you will avoid big headaches or dumplings sometimes unrecoverable.
To install it on your Ubuntu machine, nothing easier than:
sudo apt-get install shellcheck
And if you wish, it is possible to have your scripts checked via the website: https://www.shellcheck.net
Good scripting to you!