On 09/11/2012 05:51 AM, Марк Коренберг wrote:
> fun()
> {
>     echo 'Execute really bad command:'
>     /bin/false
>     echo 'should not print this'
>     return 0
> }
> 
> if ! fun; then
>     echo 'should catch fault here'

Wrong.  '! fun' is executed in a context in which 'set -e' is ignored,
so ALL commands with 'fun' are executed without error aborts, which mean
'should not print this' MUST be printed, and 'should catch fault here'
must NOT be printed.

This behavior conforms to POSIX.

> 
> Is any way to force "set -e" to work even in such cases?

No, it is already working as specified (just not the way you want).

> 
> If this question asked 1000 times, why not to answer in FAQ (
> http://tiswww.case.edu/php/chet/bash/FAQ)?

http://mywiki.wooledge.org/BashFAQ#BashFAQ.2BAC8-105.Why_doesn.27t_set_-e_.28or_set_-o_errexit.2C_or_trap_ERR.29_do_what_I_expected.3F

-- 
Eric Blake   ebl...@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to