2024年11月28日(木) 13:59 Ivan Shapovalov <inte...@intelfx.name>: > Repeat-By: > See the attached script.
I was testing the behavior of Bash, but it seems Bash's behavior has never been stable and consistent. With the following test cases #1...#8, #1 "$bash" -ec 'trap "echo \"[\$FUNCNAME:\$f]\"" EXIT; f() { local f=$FUNCNAME; false; }; f' #2 "$bash" -e <<< 'trap "echo \"[\$FUNCNAME:\$f]\"" EXIT; f() { local f=$FUNCNAME; false; }; f' #3 "$bash" -ec 'trap "echo \"[\$FUNCNAME:\$f]\"" EXIT; f() { local f=$FUNCNAME; kill -INT $$; }; f' #4 "$bash" -e <<< 'trap "echo \"[\$FUNCNAME:\$f]\"" EXIT; f() { local f=$FUNCNAME; kill -INT $$; }; f' #5 "$bash" -ec 'trap "echo \"[\$FUNCNAME:\$f]\"" EXIT; f() { local f=$FUNCNAME; kill -INT $$; :; }; f' #6 "$bash" -e <<< 'trap "echo \"[\$FUNCNAME:\$f]\"" EXIT; f() { local f=$FUNCNAME; kill -INT $$; :; }; f' #7 "$bash" -ec 'trap "echo \"[\$FUNCNAME:\$f]\"" EXIT; f() { local f=$FUNCNAME; trap : RETURN; kill -INT $$; }; f' #8 "$bash" -e <<< 'trap "echo \"[\$FUNCNAME:\$f]\"" EXIT; f() { local f=$FUNCNAME; trap : RETURN; kill -INT $$; }; f' The results with different Bash versions are these: $bash #1 #2 #3 #4 #5 #6 #7 #8 bash-2.0 (empty) (empty) (empty) (empty) (empty) (empty) (empty) (empty) bash-2.01 (empty) (empty) (empty) (empty) (empty) (empty) (empty) (empty) bash-2.02 [:] (empty) [:] (empty) [:] (empty) [:] (empty) bash-2.03 [:] [:] [:] [:] [:] [:] [:] [:] bash-2.04 [f:] [f:f] [f:f] [f:f] [f:f] [f:f] [f:] [f:f] bash-2.05a [f:] [f:f] [f:f] [f:f] [f:f] [f:f] [f:] [f:f] bash-2.05b [f:] [f:f] [f:f] [f:f] [f:f] [f:f] [f:] [f:f] bash-3.0 [f:] [f:f] [f:f] [f:f] [f:f] [f:f] [f:f] [f:f] bash-3.1 [f:] [f:f] [f:f] [f:f] [f:f] [f:f] [f:f] [f:f] bash-3.2 [f:] [f:f] (empty) [:] [f:f] [f:f] [f:f] [f:f] bash-4.0 [f:] [f:f] (empty) [:] [f:f] [f:f] [f:f] [f:f] bash-4.1 [f:] [f:f] (empty) [:] [f:f] [f:f] [f:f] [f:f] bash-4.2 [f:] [f:f] (empty) [:] [f:f] [f:f] [f:f] [f:f] bash-4.3 [f:f] [f:f] (empty) [:] [f:f] [f:f] [f:f] [f:f] bash-4.4 [f:f] [f:f] (empty) [:] [f:f] [f:f] [f:f] [f:f] bash-5.0 [f:f] [f:f] (empty) [:] [f:f] [f:f] [f:f] [f:f] bash-5.1 [f:f] [f:f] (empty) [:] [f:f] [f:f] [f:f] [f:f] bash-5.2 [f:] [f:] [:] [:] [f:f] [f:f] [f:f] [f:f] bash-dev [f:] [f:] [:] [:] [f:f] [f:f] [f:f] [f:f] Your INNER_FAIL_EXIT corresponds to #6 and/or #8, and INNER_FAIL_2 corresponds to #2. If you only look at these cases (#2, #6, and #8), one might think Bash's behavior was consistent until Bash 5.0 but suddenly broken in Bash 5.1. However, the behavioral changes have also happened in Bash 4.3, 3.2, 3.0, etc. In addition, there has never been a version where the local variable is visible in the EXIT trap in all cases.