return_in_trap1.tests 478 B

123456789101112131415161718
  1. a() {
  2. (exit 2)
  3. echo a:$?
  4. (kill -s USR1 $$; echo b:$?; exit 3)
  5. echo c:$? # does not execute
  6. (exit 4)
  7. }
  8. trap "echo Trap; return" USR1
  9. a
  10. echo d:$?
  11. # It's debatable what is the correct value above.
  12. # Does 'return' in trap see $? == 2 or $? == 3?
  13. # IOW: after (kill..), does shell first wait for its completion
  14. # and sets $?, then checks pending signals and runs a trap handler,
  15. # or does it first check pending signals and runs handler?
  16. # hush does the former, and prints 3.