<div>Hello microsuxx,<br><br>Thank you for the replies.<br><br>I did some more
manual testing, <br><br>the wait -n builtin looks kinda sketchy because of what
the bash manpage of the builtin wait says, during testing I see that wait -n is
able to detect that $? has become -1 in the trap handler command, but if the
trap handler command checks $? directly then suddenly the trap handler doesn't
run??? <br><br>Here's what I tested:<br><br><br data-mce-bogus="1"></div>
find ./ -type f -exec printf '\n\n\n{} has:\n' \; -exec cat {} \; -exec printf
'\n\nrunning command ./{}\n' \; -exec {} \; -exec printf '\n' \;
./wait.sh has:
#!/bin/bash
bash -x -e -c 'echo $(exit 1) ; wait -n ; echo survivied'
running command ././wait.sh
++ exit 1
+ echo
+ wait -n
./trap.sh has:
#!/bin/bash
bash -x -e -c 'trap '\'' (( $? )) && exit 1 '\'' debug ; echo $(ls /zzzz) ;
echo survivied '
running command ././trap.sh
+ trap ' (( $? )) && exit 1 ' debug
++ (( 0 ))
++ ls /zzzz
ls: cannot access '/zzzz': No such file or directory
+ echo
++ (( 0 ))
+ echo survivied
survivied
./script.sh has:
#!/bin/bash
set -eEuo pipefail
shopt -s inherit_errexit
echo ok
t1="$( ( ls /zzzzz | cat ; echo a1) ; echo a2 )"
if [ "$?" != "0" ]
then
exit $?
fi
echo a3
running command ././script.sh
ok
ls: cannot access '/zzzzz': No such file or directory
./wait_trap.sh has:
#!/bin/bash
bash -x -e -c 'trap '\'' wait -n ; (( $? )) && exit $? '\'' debug ; echo $(exit
1) ; echo survivied '
running command ././wait_trap.sh
+ trap ' wait -n ; (( $? )) && exit $? ' debug
++ wait -n