⚠️ 'local' used on the same line will prevent 'set -e' from aborting
⚠️ 'local' used on the same line with function call will prevent 'set -e' from aborting script
set -efoo() { echo "This is foo; returns 1 (unhappy)" return 1}main() { echo "Calling foo()" # We succeed because of 'local' being used on the same line as the function call. local foo_capture="$(foo)" echo "After foo()" echo.green "MAIN FINISHED! (after foo calls), foo_capture=[${foo_capture}]"}main "${@}"
⚠️ Some commands return non-zero in non-error cases - By default with 0 visibility
#!/usr/bin/env bashset -eecho_with_pid(){ echo "[\$\$=$$/$BASHPID] $*"}main() { echo_with_pid "START" echo "1" > /tmp/1 echo "2" > /tmp/2 # Diff will return 1 if files are not the same, this will abort the script. # # In this case we would have to adjust the code to be # diff /tmp/1 /tmp/2 || true # # For the script to NOT abort. diff /tmp/1 /tmp/2 echo "" echo_with_pid "DONE"}main "${@}"
Output
[$$=26314/26314] START1c1< 1---> 2
The more annoying part is not having to write
diff /tmp/1 /tmp/2 || true
But that when set -e halts it does NOT provide any debugging info on WHY it stopped.