Hacker News new | ask | show | jobs
by andsens 1860 days ago
It's worse than that actually, `set -e`/"errexit" is disabled for function calls in ifs. Meaning this:

    set -e
    fn() {
        false
        echo "didn't exit"
    }
    if fn; then
        echo "fn() succeeded"
    fi
will output

    didn't exit
    fn() succeeded
1 comments

Yep, likewise it’s also disabled in function calls and sub shells that are invoked in an && or || block (i.e., in the above case of you change the if statement to “fn && echo ...” you’ll see the same behavior).

Even worse, you can add the line “set -e” inside the function explicitly re-enabling it and it still won’t change the outcome because errexit wasn’t technically unset!

Yes, Oil fixes this with strict_errexit:

sibling comment: https://news.ycombinator.com/item?id=27166719

blog post: https://www.oilshell.org/blog/2020/10/osh-features.html

It needs some official documentation, but if you download Oil and see any other problems I'm interested! I think I fixed all of them.

https://github.com/oilshell/oil/wiki/Where-To-Send-Feedback