Update: the first answer by @Kusalananda is correct for the example above (adding return 0 to the control_operators function prevents the ERR signal). However, here is another example which seems to violate the “part of a && or || list” rule:
#!/usr/bin/env bash
_trap_err() {
local status=$? sig=$1 line=$2;
echo "Exit status ${status} on line ${line}: \`${BASH_COMMAND}\`";
}
trap '_trap_err ERR $LINENO' ERR;
true && false;
echo Done;
The output of this script is:
❯ test.sh
Exit status 1 on line 7: `false`
Done
The line true && false should not send an ERR signal because the command false is “part of a && or || list”. So, why did it?