On 1/8/10 12:50 PM, Stefan Götz wrote:
> Hi!
> 
> It seems that in bash version 4.0.33(1)-release (i486-pc-linux-gnu) (from 
> Ubuntu
> 9.04), ERR traps are not inherited by functions that are called via command
> substitution. I expected inheritance to apply in this case since the
> documentation of 'set -E' promises inheritance of the ERR trap for subshell
> contexts. The script below illustrates this behavior as the trap action
> err_handler() is not called.
> 
> Is this behaviour intended? Even if so, I'd like to say that I would find ERR
> trap inheritance for command substitution extremely useful :-)
> 
> Cheers,
>       Stefan
> 
> #!/bin/bash
> 
> err_handler() {
>   echo "THERE WAS AN ERROR"
> }
> 
> set -E
> trap 'err_handler' ERR
> 
> myfunc() {
>   false # fails to cause an ERR trap
>   true
> }
> 
> FOO=$(myfunc)
> exit 0

How does this script demonstrate that err_handler is not called?  The
command substitution swallows all the output, and you never look at
the results.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/


Reply via email to