Jonathan Nieder dixit: >Justification: posix [1] > >It is handy to be able to use the old exit status from an EXIT handler >by using bare "exit": > > $ sh -c 'trap "echo hi; exit" EXIT; exit 9'; echo $? > hi > 9
>[1] >http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_21_14 (Note that this would work trap 'x=$?; echo hi; exit $?' EXIT ) Question to Austin ML: EXIT STATUS The exit status shall be n, if specified. Otherwise, the value shall be the exit value of the last command executed, or zero if no command was executed. When [281]exit is executed in a [282]trap action, the last command is considered to be the command that executed immediately preceding the [283]trap action. I think the wording is ambiguous. As I read mksh’s manual page (not the standard but existing practice) the exit status in Jonathan’s trap is the one of the preceding echo even though it’s in a trap, because that echo is run inside the trap, (and here’s the ambiguity in the wording) which will overwrite the errorlevel ($? value, to you non-DOS people ☺) from the trap entry but can be preserved kind of like errno in C. >http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_24_14 EXIT STATUS The value of the special parameter '?' shall be set to n, an unsigned decimal integer, or to the exit status of the last command executed if n is not specified. If the value of n is greater than 255, the results are undefined. When [319]return is executed in a [320]trap action, the last command is considered to be the command that executed immediately preceding the [321]trap action. Care to comment? I’m thinking I won’t change the code, but then, it’s past midnight again… Thanks in advance, //mirabilos -- Sometimes they [people] care too much: pretty printers [and syntax highligh- ting, d.A.] mechanically produce pretty output that accentuates irrelevant detail in the program, which is as sensible as putting all the prepositions in English text in bold font. -- Rob Pike in "Notes on Programming in C" -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org