Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15471 > unrolled thread
| Started by | John W <jwdevel@gmail.com> |
|---|---|
| First post | 2019-10-03 17:58 -0700 |
| Last post | 2019-10-03 17:58 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Bug? `set -e` inside functions inside `$(...)` John W <jwdevel@gmail.com> - 2019-10-03 17:58 -0700
| From | John W <jwdevel@gmail.com> |
|---|---|
| Date | 2019-10-03 17:58 -0700 |
| Subject | Re: Bug? `set -e` inside functions inside `$(...)` |
| Message-ID | <mailman.934.1570163406.2651.bug-bash@gnu.org> |
Ah, got it sorted out.
Not a bug, of course (:
Bash, when not in posix mode, clears the '-e' flag in subshell environments.
On 10/3/19, John W <jwdevel@gmail.com> wrote:
> 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:
> https://stackoverflow.com/questions/58228383/bash-set-e-reset-inside-functions-when-run-via
>
> But here's my small repro program:
>
> #!/usr/bin/env bash
>
> echo "Initial: $-"
> set -eu
> echo "After set: $-"
>
> function foo() {
> echo "Inside foo: $-"
> }
> foo
>
> function bar() {
> false # I'd expect this to immediately fail
> echo "Inside bar: $-"
> }
> # When a $(...) construct is involved, 'bar' runs to completion!
> x=$(bar)
> 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
> -John
>
Back to top | Article view | gnu.bash.bug
csiph-web