Date: Wed, 17 Apr 2019 11:35:18 +0200 From: Joerg Schilling <joerg.schill...@fokus.fraunhofer.de> Message-ID: <5cb6f356.dh4k5z2xfkptm0+v%joerg.schill...@fokus.fraunhofer.de>
| If the standard did require something that is neither covered by the | historical Bourne Shell behavior We know the historical Bourne shell output the trap that was set by the user, regardless of whether that resulted in a signal being caught, or not because the signal was ignored on entry to the shell. I showed the code that did that in an earlier message. | nor ksh88 I don't have access to ksh88 to test it, but something tells me that if it did what it is claimed the standard requires, we would have been told about it by now. ksh93 doesn't... ksh93 $ (trap '' INT EMT; ksh93 -c trap) ksh93 $ What ksh93 does do however, is that if an attempt is made to trap a signal, and that doesn't result in changing the signal disposition, then after that the trap command tells you the signal is ignored... ksh93 $ (trap '' INT EMT; ksh93 -c 'trap "echo foo" INT; trap') trap -- '' INT ksh93 $ But that only happens if a trap action is set (or, obviously, if the script requests to ignore the signal) If the script requests to reset the signal to default, we're back to no output ksh93 $ (trap '' INT EMT; ksh93 -c 'trap - INT; trap') ksh93 $ That is, unless it was first set to some other state: ksh93 $ (trap '' INT EMT; ksh93 -c 'trap "" INT; trap - INT; trap') trap -- '' INT ksh93 $ (trap '' INT EMT; ksh93 -c 'trap "echo foo" INT; trap - INT; trap') trap -- '' INT All that mess just looks like bugs in ksh93 to me... yash and bosh seem to completely ignore any attempt to trap a signal that's ignored at startup (in a non-interactive shell - all these tests test non-interactive shells). bosh $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap - INT; trap') bosh $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap') bosh $ (trap '' INT EMT; $SHELL -c 'trap "echo foo" INT; trap') bosh $ (if the signal was not inored, the right thing happens) yash $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap - INT; trap') yash $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap') yash $ (trap '' INT EMT; $SHELL -c 'trap "echo foo" INT; trap') yash $ old pdksh and mksh both do ... mksh $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap - INT; trap') mksh $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap') trap -- INT mksh $ (trap '' INT EMT; $SHELL -c 'trap "echo foo" INT; trap') trap -- 'echo foo' INT mksh $ Pity about the lack of quoting around the null string action in the middle example ... but if I was forced to guess, I'd tend to assume that ksh88 probably acts that way as well (perhaps even including the missing explicit null string). I am not sure what happens exactly with zsh (what is going on) I don't usually use it, and don't understand all of its variations, but in that one I need to send an extra newline, otherwise it simply sits and waits forever... But with that newline: zsh $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap - INT; trap') zsh $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap') trap -- '' INT zsh $ (trap '' INT EMT; $SHELL -c 'trap "echo foo" INT; trap') trap -- 'echo foo' INT zsh $ The shell I generally regard as the most standards conforming of all I have seen (certainly more than its close relative, the NetBSD sh) that is, the FreeBSD shell (it seems like any time they find anytging that is different than the standard requires, they change it) does fbsh $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap - INT; trap') fbsh $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap') trap -- '' INT fbsh $ (trap '' INT EMT; $SHELL -c 'trap "echo foo" INT; trap') trap -- 'echo foo' INT fbsh $ bash is the one that is notably different... bash $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap - INT; trap') trap -- '' SIGINT trap -- '' SIGEMT bash $ (trap '' INT EMT; $SHELL -c 'trap "" INT; trap') trap -- '' SIGINT trap -- '' SIGEMT bash $ (trap '' INT EMT; $SHELL -c 'trap "echo foo" INT; trap') trap -- '' SIGINT trap -- '' SIGEMT bash $ (In each of these, $SHELL is the shell indicated by the PS1 output). kre