December 2018
Beginner
452 pages
12h 17m
English
In Chapter 9, Error Checking and Handling, we created the following construction: command || { echo "Something went wrong."; exit 1; }. As you (hopefully) remember, the || syntax means that everything on the right-hand side will only be executed if the command on the left-hand side has an exit status that is not 0. While this setup worked fine, it did not exactly increase readability. It would be much better if we could abstract our error handling to a function, and call that function instead! Let's do just that:
reader@ubuntu:~/scripts/chapter_13$ vim error-functions.shreader@ubuntu:~/scripts/chapter_13$ cat error-functions.sh #!/bin/bash###################################### Author: Sebastiaan Tammer# Version: v1.0.0# Date: ...