I don't understand how to reconcile the behavior of all three of these in debian's bash 5.2.15(1):

$ bash -c $'trap \'echo hello;false\' USR1 && kill -s USR1 $$ && echo here $?'
hello
here 0
$ bash -c $'trap \'echo hello;false\' USR1 && kill -s USR1 9876543; echo here $?'
bash: line 1: kill: (9876543) - No such process
here 1
$ bash -c $'trap \'echo hello;false\' USR1 && kill -s USR1 $$ 9876543; echo here $?'
bash: line 1: kill: (9876543) - No such process
hello
here 0

1) The previous statement returns 0 but the trap handler returns 1, so the next statement sees zero. 2) The previous statement returns 1, the trap handler doesn't run, so the next statement sees 1. 3) The previous statement returns 1 and the trap handler returns 1, so the next statement sees zero...?

$ kill -s CONT $$ 9876543
bash: kill: (9876543) - No such process
$ echo $?
0

Ah. Bash's builtin kill doesn't return 1 unless it couldn't send ANY signals.

$ bash -c $'trap \'echo hello;false\' USR1 && /bin/kill -s USR1 $$ 9876543; echo here $?'
/bin/kill: (9876543): No such process
hello
here 1
$ bash -c $'trap \'echo hello\' USR1 && /bin/kill -s USR1 $$ 9876543; echo here $?'
/bin/kill: (9876543): No such process
hello
here 1

Ok, so bash's trap handler discards the return code and preserves the earlier value, and my confusion was that bash's "kill" command returns 0 for some errors.

Rob
_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to