bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ERR trap inheritance in command substitution


From: DennisW
Subject: Re: ERR trap inheritance in command substitution
Date: Sun, 10 Jan 2010 03:07:02 -0800 (PST)
User-agent: G2/1.0

On Jan 8, 11:50 am, Stefan Götz <stefan.go...@cs.rwth-aachen.de>
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
>
>  signature.asc
> < 1KViewDownload

Change your error handler to output to stderr:

err_handler() {
  echo "THERE WAS AN ERROR" >&2
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]