Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: Christoph Gysin Newsgroups: gnu.bash.bug Subject: Re: command substitution is stripping set -e from options Date: Sat, 3 Oct 2015 11:35:11 +0300 Lines: 33 Approved: bug-bash@gnu.org Message-ID: References: <560D83DA.9020405@redhat.com> <20151002122925.GK25574@eeg.ccf.org> <20151002132221.GL25574@eeg.ccf.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: usenet.stanford.edu 1443861356 22641 208.118.235.17 (3 Oct 2015 08:35:56 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Greg Wooledge Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=uMD6efRy6i7KM+2SBPmP+1ff3+eMUp67a5AkjNhZXmU=; b=OzF1iSUbOrHZJpSzT0SVlcMXiNfwTC4sLa3HN46JRyE9Idzl8zFK5imVWscpK6E6Sv K0Do1stV5yTKwcbRW/miOmq192YMEURpJUzZQxbntZFxAP+XPgsi1n2XxUOQT2a9QmrN psGct9SzM+Scn+yh36UMRb2FaA56ZTqZ0F9RyOdUIVc2H7BAYMOXdoW37Ll17uJpRL0s CXpLzHgYVBZTGYZk/GmixjKhNBupqB7SxPp/3NrePGs7r6nmH8mZkZWClJAJdKf73gop iojp22VQzxWE7moV9nrjwGW71Ee+UEjYiiwLYWyue3WaXNYVV/7ZY1v2sc0nj8FhaX6q WeSA== X-Received: by 10.112.139.201 with SMTP id ra9mr7337362lbb.29.1443861351279; Sat, 03 Oct 2015 01:35:51 -0700 (PDT) In-Reply-To: <20151002132221.GL25574@eeg.ccf.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22b X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11577 > Chet can give the definitive answer, but my take is that it's a huge > surprise to someone writing a function independent of the script, or > using a function that was written independently of the script. If the > function does not expect set -e to be in effect (which is not the default, > and is not done in any sane environment, so why would anyone EXPECT it?) > then it may have been written to work in a normal environment, and will > fail in a set -e environment. Yes, obviously you can't just source other bash files and assume they work with set -e (or set -u for that matter). But if I do I still have the option of consciously disabling said options with set +e. > I have many examples of commands that surprisingly explode and set your > house on fire when run in a set -e environment, but which work perfectly > well in a regular environment. See http://mywiki.wooledge.org/BashFAQ/105 Thanks for that excellent resource! Maybe I spent too much time with bash scripts, but I'm already aware of all those corner cases. Yes they are not pretty, but for each of them there is a simple workaround. Tools like shellcheck will even warn you about some of them. The behaviour I describe seems to fall in a different category though. Switching to posix mode has all kinds of other side effects, so I don't think that's a valid workaround. And it seems that the code to inherit set -e is already there, just not enabled by default. This seems to cause behaviour that is counter-intuitive IMO. Chris