[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: more efficient AS_EXIT
From: |
Ralf Wildenhues |
Subject: |
Re: more efficient AS_EXIT |
Date: |
Tue, 18 Nov 2008 22:18:22 +0100 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
Wait ...
* Eric Blake wrote on Tue, Nov 18, 2008 at 06:03:51PM CET:
> +Portable scripts should not use @samp{set -e} if @command{trap} is used
> +to install an exit handler. This is because Tru64/OSF 5.1 @command{sh}
> +enters the trap handler with the exit status of the command prior to the
> +one that triggered the errexit handler:
> +
> address@hidden
> +$ @kbd{bash -c 'trap '\''echo $?'\'' 0; set -e; false'}
> +1
> +$ @kbd{sh -c 'trap '\''echo $?'\'' 0; set -e; false'}
> +0
This isn't correct. Even Tru64 sh will echo 1 in this case.
Hmm. This exposes it:
$ sh -ec 'trap '\''echo $?'\'' 0; false;'
0
But at the same time:
$ sh -c 'set -e; trap '\''echo $?'\'' 0; false;'
1
Weird.
> +
> address@hidden
> +Thus, when writing a script in M4sh, rather than trying to rely on
> address@hidden -e}, it is better to append @samp{|| AS_EXIT([$?])} to any
> +statement where it is desirable to abort on failure.
Cheers,
Ralf
- Re: more efficient AS_EXIT, Eric Blake, 2008/11/18
- Re: more efficient AS_EXIT, Eric Blake, 2008/11/18
- Re: more efficient AS_EXIT, Paolo Bonzini, 2008/11/19
- Re: more efficient AS_EXIT, Eric Blake, 2008/11/19
- Re: more efficient AS_EXIT, Paolo Bonzini, 2008/11/20
- Re: more efficient AS_EXIT, Eric Blake, 2008/11/20
- Re: more efficient AS_EXIT, Paolo Bonzini, 2008/11/21
- Re: more efficient AS_EXIT, Eric Blake, 2008/11/21