From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8229 invoked by alias); 12 Oct 2012 13:55:45 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30730 Received: (qmail 16987 invoked from network); 12 Oct 2012 13:55:42 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at case.edu designates 129.22.105.36 as permitted sender) Message-ID: <50781FEC.3090309@case.edu> Date: Fri, 12 Oct 2012 09:49:32 -0400 From: Chet Ramey Reply-To: chet.ramey@case.edu User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: Peter Stephenson CC: zsh-workers@zsh.org, chet.ramey@case.edu Subject: Re: set -e (no && or ||) References: <20121012110542.314890@gmx.com> In-Reply-To: X-Enigmail-Version: 1.4.4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Junkmail-Whitelist: YES (by domain whitelist at mpv1.tis.cwru.edu) On 10/12/12 7:53 AM, Peter Stephenson wrote: > On Fri, 12 Oct 2012 07:05:41 -0400 > Sergey Fadeev wrote: > >> Why doesn't it exit the shell? >> $ set -e >> $ echo $(false) >> Shouldn't the error code of $(false) command substitution be checked >> by set -e before passing stdout to the echo builtin? > > No, because the command was "echo", and that didn't fail. Exit status > effectively means exit status seen by the main shell command > interpreter ($?), although I'm sure there are some subtleties I haven't > thought about. > > The way to get the status of a substitution to fail is to use an > assignment: > > output=$(false) > > which does cause the shell to exit on failure, because it would set $? to > 1. This is standard shell behaviour, though I can't point to where in > the standard it says. 2.9.1 Simple Commands If there is a command name, execution shall continue as described in Command Search and Execution. If there is no command name, but the command contained a command substitution, the command shall complete with the exit status of the last command substitution performed. Otherwise, the command shall complete with a zero exit status. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/