▲ 107 ▼ Error handling in bash (notifox.com) submitted 6 months ago by BlackEco@lemmy.blackeco.com to c/programming@programming.dev 29 comments fedilink hide all child comments
[–] IanTwenty@piefed.social 7 points 6 months ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] Oinks@lemmy.blahaj.zone 4 points 6 months ago* 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. permalink fedilink source parent
[–] Oinks@lemmy.blahaj.zone 4 points 6 months ago* 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. permalink fedilink source parent