There is two different ways to execute scripts. First one is to execute it as a executable that contains interpreter. Second one is dot command which is interpreded by shell that executes script file.
Executable that has an interpreter has on first line #!/path/to/interperter. Dot command may or may not have #! markup.
Copy script above to file script.sh and give executable bit on it by comman chmod 755 script.sh. First run script like this "./script.sh" and try then ". script.sh" Rerun script both ways until you understand what interpreter line does and how. Ps, dot command sees first line as a comment if you wonder the outputs.