On Thu, Sep 25, 2025 at 08:53:45 -0600, Stan Marsh wrote: > As I've argued in the past, it is a good "last fallback". That is, > you set -e, but you still do all the usual error handling for the > expected cases. The point here is that literally *anything* you do, > could error out. For example, a perfectly normal: > > echo "This is a message" > afile > > could error for a number of reasons. You might run out of disk space. > You might be in a write-protected directory. Even if you use > /tmp/afile, some wayward admin might have made /tmp non-writable. The > disk might have a head crash. The drive might have gone read-only > (say, it was an SD card). Etc. > > All of these things are extremely unlikely, of course, but if any of > them does happen, you want your script to exit immediately. And you > really don't want to have to write explicit error-handling code for > every single trivial line such as the above example.
I dispute the claim that you want your script to exit immediately if any write to any file fails. In some cases this is true, but it's not universal. This might be an attempt at logging, which is nice to have but not essential. The fundamental operation of the script might not depend on having this message written to this file, in which case this is a condition for which the script might issue an error message on a different channel (e.g. to the user's terminal) letting them know about the logging failure, but then carry on anyway.