The bash man page says:
Exit immediately if the pipeline (which may consist of one simple command)
a head restraint command enclosed in parentheses, or one of the commands executed as part of a list of commands enclosed in braces ...
So, I suggested that the function should be considered as a list of commands, enclosed in curly braces. However, if you apply a conditional expression to a function call, errexit is no longer stored inside the function body, and it returns the entire list of commands before returning. Even if you explicitly create a subshell inside a function with the errexit function enabled for that subshell, all the commands in the command list are executed. Here is a simple example demonstrating the problem:
function a() { b ; c ; d ; e ; } function ap() { { b ; c ; d ; e ; } ; } function as() { ( set -e ; b ; c ; d ; e ) ; } function b() { false ; } function c() { false ; } function d() { false ; } function e() { false ; }
( set -Eex ; a ) + a + b + false
( set -Eex ; ap ) + ap + b + false
( set -Eex ; as ) + as + set -e + b + false
Now, if I applied the condition to each of them ...
( set -Eex ; a || false ) + a + b + false + c + false + d + false + e + false + false
( set -Eex ; ap || false ) + ap + b + false + c + false + d + false + e + false + false
( set -Eex ; as ) + as + set -e + b + false + c + false + d + false + e + false + false
bash
Craig
source share