bug-bash
[Top][All Lists]
Advanced

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

Re: [RFC] Logically composable variant of errexit


From: Ángel González
Subject: Re: [RFC] Logically composable variant of errexit
Date: Fri, 10 Oct 2014 18:16:56 +0200

On Andreas Grünbacher wrote:
> With errexit, you get vastly different results from functions depending
> on how the functions are called, for example,
> 
>    foo() {
>       echo "foo: top"
>       false
>       echo "foo: bottom"
>    }
> 
>    set -o errexit
> 
>    # bottom of foo reached:
>     if foo; then
>       echo "success"  # reached
>    fi
> 
>    # bottom of foo not reached:
>    foo
> 
> With errfail, "foo:bottom" and "success" would not be reached.

I disagree. IMHO the function should have the errfail value of its
parent scope at the time of its definition.

Otherwise, a function expecting to ignore errors would mysteriously fail
in a script that set -o errexit, unaware that one of the commands it
calls is [shadowed by] a function.

Thus, you would have to put the set at the top for the behavior you expected.


> Command substitutions would continue to behave as basic commands
> do with respect to control flow: inside functions, a failure would cause
> the function to return; outside of functions, the script would exit.

+1




reply via email to

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