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: Re: Bug? `set -e` inside functions inside `$(...)` Date: Thu, 3 Oct 2019 17:58:02 -0700 Lines: 57 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 1570163407 29211 209.51.188.17 (4 Oct 2019 04:30:07 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:in-reply-to:references:from:date:message-id:subject:to; bh=QUYp0OPnFTLfjcGJbP7xKO/RjngJqVSLP1GUooT8vhk=; b=lxERGgpu+EH8S4LiSrziHIkXuX7S0Q3j28R+u0TbCkoPKmpAj1JudIdDOBje4DOWSk wIa8Z8BDLUV8PO4RBNt2faau892INfuIdAmRZVSPhT9CsxlZ0NAZLkLU7+XgDU7BYgVQ h5KWZh5K4jS7D2e66FjToA4M+5P0wQjfRsTPAzi9q8UttUTZWVfLj4q8ARjWUyISOoTS bxOooJDvFW21mQ4UaQLNcT5JNG2WQPOUG2/lSV0oY2TVMkDlKkD/yRJFM4Xn+oqtxh+v b6OLzA7hYGNI9u1K0MzMMS5w97F50rxhhdM7GHthe5z3n9Pq4xFo6IfnM3eZFr6JCrZ3 fHfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=QUYp0OPnFTLfjcGJbP7xKO/RjngJqVSLP1GUooT8vhk=; b=XnEP2xDzM7RG4KAPptvYoHVhgSePA1DkBOxmHZGDazgKhjDj+uQahvFwYSY1pPf1tO 909gI/ZCEQKnPIXwvz2O1AgfNGWAyEJX4+rRT66H2Xy38HSBY1vnJ1MDeCc9jpNiE8E8 omiNKtYGMmFCiZQthemNjLsOg6ytdOrQ5e3/1mCByX8ZEDHhtdKnSL0oRC4OcRaYwV+0 bW9YDnqQMLaNRZzblayd3RQjS4IO4cFElpGbwAy49OpPizdmzQC8Y5GLzR31WtISgTTM kqJ8WOP0RwSyiJNt6qDElgUHiguf93if6OntPhgdy1IDetYeigRL0jWz9JVMjSWbVkk7 ltTg== X-Gm-Message-State: APjAAAUynDMScqlacCmPZTMMmQi9cyZSZ/GzPXjtMRqFpLTj6eIhqzqw JS8i0My0oR0PB33Mr89luHdxy/SOBH/+m83fYyDh0Q== X-Google-Smtp-Source: APXvYqx3Nw3cLg311KCaChZW1QsBoL4VO6uBpWhhz7UCedAArrDTOdBsxF3UAFrXrCFiBvDI90xOJ1pg5f28UqauMuo= X-Received: by 2002:adf:fe05:: with SMTP id n5mr864537wrr.355.1570150683158; Thu, 03 Oct 2019 17:58:03 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42f 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: X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:15471 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 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 >