Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't know what this does:

    set -Eeuo pipefail
But I do know this one, which appears to be missing one:

    set -o pipefail -o errexit -o nounset
So, one step up: Use long options and long names. Make it readable, and not just writable.


You are missing:

> E If set, any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell environment. The ERR trap is normally not inherited in such cases.

set -eu is at least 30 years old. Not sure whether it makes sense to rewrite established code.


You're missing `errtrace` (-E) which means "any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell environment"

You probably haven't used it much if you haven't been using `trap`


I use just

   trap EXIT
With

   set -eu
errors in subshells should lead to an exit anyway, so my exit handler is called. Or am I missing some case?


I can't think of any difference if you're trapping both with the same handler. Probably only if you want a separate handler for ERR vs EXIT.


I often set up a temporary directory at the beginning and then clean it up in an EXIT trap. Adding ERR and errtrace (-E) would remove the tmpdir or the first failure anywhere, no matter if it's a recoverable one.

So I'm sticking with just set -eu and trap EXIT...


Yes! I read this somewhere a little while back and have been doing it exclusively since. Makes tons of sense.

Usually I have to look up what the long options are, since I've generally only memorized the short ones, but it helps immensely with readability, particularly for someone who hasn't memorized the short ones, who can now just semantically understand the options.


long options often cause issues since a few comon executables are only short-flag compatible between OSs




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: