Command below in interactive shell produces the error which is explained in other questions:
$ echo "Hello World !"
-bash: !": event not found
Why is the error gone when put in a shell script file and executed?
cat <<EOT > test.sh
#!/bin/sh
VAR=1
echo "Hello World !$VAR"
echo "Hello World !2"
echo "Hello World !3"
EOT
None of below produce the error!
chmod a+x ./test.sh
./test.sh
bash ./test.sh
sh ./test.sh
source ./test.sh