2008-10-25 Eric Blake <ebb9@byu.net>
+ Document AS_EXIT.
+ * doc/autoconf.texi (Common Shell Constructs) <AS_EXIT>: Document
+ this macro.
+ (Limitations of Builtins): Mention AS_EXIT.
+ * NEWS: Mention it.
+
Use AS_EXIT in autoconf.as.
* bin/autoconf.as: Consistently use AS_EXIT.
AS_LINENO_PREPARE AS_ME_PREPARE AS_VAR_APPEND AS_VAR_COPY
** The following m4sh macros are documented now:
- AS_ECHO AS_ECHO_N AS_LITERAL_IF AS_UNSET AS_VAR_IF AS_VAR_POPDEF
- AS_VAR_PUSHDEF AS_VAR_SET AS_VAR_SET_IF AS_VAR_TEST_SET
- AS_VERSION_COMPARE
+ AS_ECHO AS_ECHO_N AS_EXIT AS_LITERAL_IF AS_UNSET AS_VAR_IF
+ AS_VAR_POPDEF AS_VAR_PUSHDEF AS_VAR_SET AS_VAR_SET_IF
+ AS_VAR_TEST_SET AS_VERSION_COMPARE
** The m4sh macros AS_IF and AS_CASE can now be used in shell lists.
The responsibility for supplying a trailing newline now belongs to
Redirections can be placed outside the macro invocation.
@end defmac
+@defmac AS_EXIT (@dvar{status, 1})
+@asindex{EXIT}
+Emit code to exit the shell with @var{status}. This works around shells
+that see the exit status of the command prior to @code{exit} inside a
+@samp{trap 0} handler (@pxref{Limitations of Builtins, , Limitations of
+Shell Builtins}).
+@end defmac
+
@defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false})
@asindex{IF}
Run shell code @var{test1}. If @var{test1} exits with a zero status then
The portable solution is then simple: when you want to @samp{exit 42},
run @samp{(exit 42); exit 42}, the first @command{exit} being used to
set the exit status to 42 for Zsh, and the second to trigger the trap
-and pass 42 as exit status for Bash.
+and pass 42 as exit status for Bash. In m4sh, this is covered by using
+@code{AS_EXIT}.
The shell in Free@acronym{BSD} 4.0 has the following bug: @samp{$?} is
reset to 0 by empty lines if the code is inside @command{trap}.