function test_ok {
echo "function without error" || { echo "[Error] text"; return 1; }
echo "this is executed"
}
function test_nok {
echo "function with error"
cause-an-error || { echo "[Error] text"; return 1; }
echo "this is not executed"
echo "this is not executed"
}
test_ok ; echo "$?"
test_nok ; echo "$?"
I would expect that the return 1 in function test_nok only exits the nested function { echo "[Error] text"; return 1; } and the following two echo commands are executed as they belong to the parent function test_nok.
But that's not true, echo "this is not executed" really is not executed and the exit code of test_nok is 1. This is the behavior I need, but I do not understand why it works that way => why is echo "this is not executed" not executed?
{ }isn't a function, it just groups commands.(...)instead of a group{...}.