you are viewing a single comment's thread
view the rest of the comments
[–] 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

  • source
  • parent
  • hideshow 2 child comments
  • [–] 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.

  • source
  • parent