[Top][All Lists]

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

Bug? `set -e` inside functions inside `$(...)`

From: John W
Subject: Bug? `set -e` inside functions inside `$(...)`
Date: Thu, 3 Oct 2019 17:27:03 -0700

I'm seeing some strange behavior w/regard to `set -e` when invoking a
shell function through a `$(...)` construct.

I can't tell if it's a bug or not; the manpage doesn't really mention
$() specially with regard to `set -e`, that I have found.

I made a SO post with a bunch of details here:

But here's my small repro program:

    #!/usr/bin/env bash

    echo "Initial:    $-"
    set -eu
    echo "After set:  $-"

    function foo() {
        echo "Inside foo: $-"

    function bar() {
        false    # I'd expect this to immediately fail
        echo "Inside bar: $-"
    # When a $(...) construct is involved, 'bar' runs to completion!
    echo "We should never get here ... but we do."
    echo "$x"

For me, this ouputs:

    Initial:    hB
    After set:  ehuB
    Inside foo: ehuB
    We should never get here ... but we do.
    Inside bar: huB

and it's really the last two lines that confuse me. Why was 'set -e'
disabled inside of "bar"?

Is this documented behavior, and I missed it?
Or a bug?
Or makes sense under some interpretation of things that I'm not grasping?

Thanks for any advice

reply via email to

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