Dmitry V. Levin wrote:
> This would break the "If removal fails" statement.
> Let's pass exit code to this function as an argument:
>
> remove_tmp_()
> {
> __st=$1
> [...]
> trap 'remove_tmp_ $?' 0
Yes, you're right. Here's an updated proposed patch:
2010-01-30 Bruno Haible <[email protected]>
Dmitry V. Levin <[email protected]>
Avoid unportable use of $? at the beginning of a shell function.
* tests/init.sh (remove_tmp_): Don't retrieve the exit status here.
(setup_): Do it directly in the trap handler here.
--- tests/init.sh.orig Sun Jan 31 02:07:31 2010
+++ tests/init.sh Sun Jan 31 02:07:10 2010
@@ -79,10 +79,10 @@
testdir_prefix_() { printf gt; }
# Run the user-overridable cleanup_ function, remove the temporary
-# directory and exit with the incoming value of $?.
+# directory and exit with the code passed as first argument.
remove_tmp_()
{
- __st=$?
+ __st=$1
cleanup_
# cd out of the directory we're about to remove
cd "$initial_cwd_" || cd / || cd /tmp
@@ -127,7 +127,7 @@
# This pair of trap statements ensures that the temporary directory,
# $test_dir_, is removed upon exit as well as upon catchable signal.
- trap remove_tmp_ 0
+ trap 'remove_tmp_ $?' 0
trap 'Exit $?' 1 2 13 15
}