Whatever error message you get after pressing Enter, that error will get stored in log.txt. Now view the contents of log.txt as follows:
$ cat log.txt
So, in this way, you can avoid warnings as well as errors. Now, run the script as:
$ bash avoid_error.sh 2> log.txt
The error message will get stored in log.txt. You can view it by running the cat log.txt command.