How it works...

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.

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.