Reported by Tim Van Holder.
+2001-01-16 Akim Demaille <akim@epita.fr>
+
+ * m4sh.m4 (AS_EXIT): Don't rely on exit == exit $?.
+ Reported by Tim Van Holder.
+
2001-01-16 Akim Demaille <akim@epita.fr>
* Makefile.am (editpl, editsh): Merge into...
Stu Grossman grossman@cygnus.com
Syd Polk spolk@cygnus.com
T.E. Dickey dickey@clark.net
-Theodore Ts'o" tytso@MIT.EDU
-Thomas Winder tom@vlsivie.tuwien.ac.AT
+Theodore Ts'o" tytso@mit.edu
+Thomas Winder tom@vlsivie.tuwien.ac.at
+Tim Van Holder tim.van.holder@pandora.be
Tom Lane tgl@sss.pgh.pa.us
Tom Purcell Tom.Purcell@wang.com
Tom Tromey tromey@cygnus.com
@item @command{exit}
@c -----------------
@cindex @command{exit}
-@c FIXME: A better merging between this item and `trap' is welcome.
+The default value of @command{exit} is supposed to be @code{$?},
+unfortunately some shell, such as the @sc{djgpp} port of Bash 2.04, just
+perform @samp{exit 0}.
+
+@example
+bash-2.04$ foo=`exit 1` || echo fail
+fail
+bash-2.04$ foo=`(exit 1)` || echo fail
+fail
+bash-2.04$ foo=`(exit 1); exit` || echo fail
+bash-2.04$
+@end example
+
+Using @samp{exit $?} restores the expected behavior.
+
Some shell scripts, such as those generated by @command{autoconf}, use a
trap to clean up before exiting. If the last shell command exited with
nonzero status, the trap also exits with nonzero status so that the
@c -----------------
@cindex @command{trap}
It is safe to trap at least the signals 1, 2, 13 and 15. You can also
-trap 0, i.e., have the trap run when the script end (either via an
+trap 0, i.e., have the trap run when the script ends (either via an
explicit @command{exit}, or the end of the script).
Although @sc{posix} is not absolutely clear on that point, it is widely
set the exit status to 42 for Zsh, and the second to trigger the trap
and pass 42 as exit status for Bash.
-Note that in Bourne shell an unqualified @command{exit} is equivalent to
-@samp{exit $?}, hence you may actually abbreviate it as @samp{(exit 42);
-exit}.
-
-The shell in FreeBSD 4.0 has the following bug: @samp{ $?} is reset to 0
+The shell in FreeBSD 4.0 has the following bug: @samp{$?} is reset to 0
by empty lines if the code in inside trap.
@example
# We cannot simply use "exit N" because some shells (zsh and Solaris sh)
# will not set $? to N while running the code set by "trap 0"
# So we set $? by executing "exit N" in the subshell and then exit.
+# Other shells don't use `$?' as default for `exit', hence just repeating
+# the exit value can only help improving portability.
m4_define([AS_EXIT],
-[{ (exit m4_default([$1], 1)); exit; }])
+[{ (exit m4_default([$1], 1)); exit m4_default([$1], 1); }])
# AS_IF(TEST, [IF-TRUE], [IF-FALSE])
# We cannot simply use "exit N" because some shells (zsh and Solaris sh)
# will not set $? to N while running the code set by "trap 0"
# So we set $? by executing "exit N" in the subshell and then exit.
+# Other shells don't use `$?' as default for `exit', hence just repeating
+# the exit value can only help improving portability.
m4_define([AS_EXIT],
-[{ (exit m4_default([$1], 1)); exit; }])
+[{ (exit m4_default([$1], 1)); exit m4_default([$1], 1); }])
# AS_IF(TEST, [IF-TRUE], [IF-FALSE])