On Andreas Grünbacher wrote: > With errexit, you get vastly different results from functions depending > on how the functions are called, for example, > > foo() { > echo "foo: top" > false > echo "foo: bottom" > } > > set -o errexit > > # bottom of foo reached: > if foo; then > echo "success" # reached > fi > > # bottom of foo not reached: > foo > > With errfail, "foo:bottom" and "success" would not be reached.
I disagree. IMHO the function should have the errfail value of its parent scope at the time of its definition. Otherwise, a function expecting to ignore errors would mysteriously fail in a script that set -o errexit, unaware that one of the commands it calls is [shadowed by] a function. Thus, you would have to put the set at the top for the behavior you expected. > Command substitutions would continue to behave as basic commands > do with respect to control flow: inside functions, a failure would cause > the function to return; outside of functions, the script would exit. +1