From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19571 invoked by alias); 2 Jan 2015 17:02:15 -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: 34077 Received: (qmail 1627 invoked from network); 2 Jan 2015 17:01:59 -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 autolearn=ham version=3.3.2 X-Originating-IP: [86.6.153.127] X-Spam: 0 X-Authority: v=2.1 cv=AoZg3YNP c=1 sm=1 tr=0 a=39NrsSuza2clQiZR/7fYWQ==:117 a=39NrsSuza2clQiZR/7fYWQ==:17 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=q2GGsy2AAAAA:8 a=HYshxDoSAAAA:8 a=FZxgREb3DvYqP9PVqNQA:9 a=CjuIK1q_8ugA:10 Date: Fri, 2 Jan 2015 16:56:23 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: [PATCH] ERR_EXIT with "for" loops and shell functions (Re: Bug report) Message-ID: <20150102165623.7c4e3dd1@ntlworld.com> In-Reply-To: <141227163220.ZM11821@torch.brasslantern.com> References: <20141226165344.GC1003@basilisk> <141226183516.ZM18384@torch.brasslantern.com> <141227163220.ZM11821@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 27 Dec 2014 16:32:20 -0800 Bart Schaefer wrote: > On Dec 26, 6:35pm, Bart Schaefer wrote: > } > } This is very tricky because we have to propagate the value of $? from > } before the "for" keyword (including before the start of the function) > } into the "do" body, but must *not* *use* the value of $? for deciding > } whether to exit-on-error, because the nonzero value came from an "if" > } test. There is a "noerrexit" flag that is supposed to cover this case, > } but it's not set when the very first "sublist" in a function body is > } a for-loop (there are likely to be other similar cases). > > The following patch attempts to fix all of this weirdness. I had a look at this myself while in 2Gnetworkland, and sent a couple of messages which didn't get through quite possibly because the gmail app sent them to zsh-hackers@zsh.org for undetermined reasons. However, you must have found everything I did since the tests I added now pass. They're all just for status, nothing specific to ERR_EXIT or ERR_RETURN; I didn't find I needed to change anything there in the main code, just for the status value itself. They overlap with yours but that's no big deal. Here they are. diff --git a/Test/A07control.ztst b/Test/A07control.ztst index 397a821..b1a2487 100644 --- a/Test/A07control.ztst +++ b/Test/A07control.ztst @@ -110,3 +110,56 @@ done 1:break error case -1 ?(eval):break:2: argument is not positive: -1 + + false + for x in; do + print nothing executed + done +0:Status 0 from for with explicit empty list + + set -- + false + for x; do + print nothing executed + done +0:Status 0 from for with implicit empty list + + (exit 2) + for x in 1 2; do + print $? + done +0:Status from previous command propagated into for loop +>2 +>0 + + false + for x in $(echo 1 2; (exit 3)); do + print $? + done +0:Status from expansion propagated into for loop +>3 +>0 + + false + for x in $(exit 4); do + print not executed + done +0:Status from expansion not propagated after unexecuted for loop + + false + for x in NonExistentFilePrefix*(N); do + print not executed, either + done +0:Status from before for loop not propagated if empty after expansion + + for x in $(echo 1; false); do + done +0:Status reset by empty list in for loop + + false + for x in $(echo 1; false); do + echo $? + (exit 4) + done +4:Last status from loop body is kept even with other funny business going on +>1 -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/