Most bash scripts are very brittle because error handling is an afterthought. In this blogpost you'll learn about the easiest ways to gracefully catch and handle errors. Best practices and common pitfalls.
Errors in command substitution e.g. $(cat file) are ignored by ‘set -e’, one example of its confusing nature. It does not force you to all handle errors, just some errors and which ones depends on the code you write.
This is a great article. I just want to highlight this insane behavior in particular (slightly dramatized):
set -e
safeDelete() {
false
# Surely we don't reach this, right?
echo "rm $@ goes brr..."
}
if safeDelete all of my files; then
: # do more stuff
fi
Frankly if you actually need robustness (which is not always), you should be using a real programming language with exceptions or result types or both (i.e. not C). UNIX processes are just not really up to the task.
Errors in command substitution e.g. $(cat file) are ignored by ‘set -e’, one example of its confusing nature. It does not force you to all handle errors, just some errors and which ones depends on the code you write.
https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail
This is a great article. I just want to highlight this insane behavior in particular (slightly dramatized):
Frankly if you actually need robustness (which is not always), you should be using a real programming language with exceptions or result types or both (i.e. not C). UNIX processes are just not really up to the task.