help-bash
[Top][All Lists]
Advanced

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

Re: errortracing inside || and eval


From: Greg Wooledge
Subject: Re: errortracing inside || and eval
Date: Wed, 30 Nov 2022 10:03:49 -0500

On Wed, Nov 30, 2022 at 02:56:51PM +0100, Tycho Kirchner wrote:
> Hi!
> We would like to run an error trap inside a function, even if it is called 
> within || -> func || true.
> While bash's manpage documents in the trap-section that no error trap runs
> "if the failed command ... is part of a command executed in ||", we found the 
> following workaround, using "eval":
> 
> test.sh
> _________________________________-
> 
> func(){
>     # works if inside 'eval', otherwise trap '..' ERR has no effect.
>     eval "trap 'echo local error trap >&2;return 42' ERR; false"
>     echo func
>     return 3
> }
> 
> set -o errtrace
> trap 'echo global error trap >&2; exit 1' ERR
> 
> func || echo bye $?
> _________________________________
> 
> $ ./test.sh
> local error trap
> bye 42
> 
> 
> 
> Is this a bug or expected behavior, we can rely on?

At first glance, I'd say it's a bug that your "eval workaround" has
any effect.  It should do nothing.



reply via email to

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