[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ERR trap inheritance in command substitution
From: |
Chet Ramey |
Subject: |
Re: ERR trap inheritance in command substitution |
Date: |
Fri, 08 Jan 2010 16:47:10 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 |
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 chet@case.edu http://cnswww.cns.cwru.edu/~chet/