Path: csiph.com!3.us.feeder.erje.net!feeder.erje.net!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: John W Newsgroups: gnu.bash.bug Subject: Bug? `set -e` inside functions inside `$(...)` Date: Thu, 3 Oct 2019 17:27:03 -0700 Lines: 49 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1570163406 29210 209.51.188.17 (4 Oct 2019 04:30:06 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=kTH7hWtw5lmukGhGHLj5Jb1WN4+ZoUGhJ5q6sMz/noI=; b=NOR59X4NAZXb1XEvRQgUTe54ENxY/Wfk5z7CpHe00eDaofY5IZC7NIY39TAC2ThgMV BXfsURhvxQ1sxkfCA9khoY6hZHajTECBuPui/muBDcNFEKVTCHhf5X3+xdx18TQMZXtg 5HmXsR3m9qu1MjMDCGQQGJsJNOzfTEHICjHuV0/gM3wSBqPjYfmNagRkPvhBVmcBatJL EiGQJ1qUunt4yEHyYczlBqkNYmIwTmrKvT/FJkRYUVufvzOXEbdxjW8x7D/hy9iF82lx xwsuwbm4DDMyOeuAVIAdT25QQKdSHOCFFP3vt5pw2XPornTvGOin0X1WcjXlm1v/vJkQ TgPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=kTH7hWtw5lmukGhGHLj5Jb1WN4+ZoUGhJ5q6sMz/noI=; b=PRZHoY+3Dqqr95Q9o0PlNo61RppAhAhhqEP9lEBFX7i3mnfL0OiUUVAlhJU+MvDRve EQd7B1wLbPuaVzERPedHA8lrYKARjnvEfqPiJUOhIg2iYF2fTsAOojNhL8pOm725vIxP SZGBaZi6o8Sdjt9mDY8Mf/UBW6H2PAuAWcRq8Uzild8t9SerzAyjWVsr6mGjWEqZrvZi W4m6anL+TTs0l0Rg4iLd++G/i0KnsS1WntD0d5SE7PThLoF84KDAAD1IqGIEKDhNPg2P dndc3EEkYQAqKg+HCgpsMFoM0wM0yNzq+rCMDRQ/9ZSE9D8lsy5uQIrTiUqmvrbrhJ7t rYKA== X-Gm-Message-State: APjAAAWFrvyp0SYfBR5f0yfnEbbNsOdZXRGr5g4imwJ/801ijTFdR0Tf glr88XP1m1rFS0Uls7dhFvF5Evp9WPDceHR9JLQKsg== X-Google-Smtp-Source: APXvYqyQrLDFX2Lt/JLei6jMfDsFdy/9HpV5pLIkF10ExycRSELd7nL0w5BhbKgo9RHpWech8NSxS3aZtcMomzpw1EI= X-Received: by 2002:adf:f18e:: with SMTP id h14mr9490059wro.143.1570148824431; Thu, 03 Oct 2019 17:27:04 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 X-Mailman-Approved-At: Fri, 04 Oct 2019 00:30:04 -0400 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: Xref: csiph.com gnu.bash.bug:15470 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