From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17607 invoked from network); 10 May 2006 19:12:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,FORGED_RCVD_HELO autolearn=ham version=3.1.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 10 May 2006 19:12:51 -0000 Received: (qmail 43542 invoked from network); 10 May 2006 19:12:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 10 May 2006 19:12:45 -0000 Received: (qmail 7477 invoked by alias); 10 May 2006 19:12:43 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22439 Received: (qmail 7466 invoked from network); 10 May 2006 19:12:42 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 10 May 2006 19:12:42 -0000 Received: (qmail 43267 invoked from network); 10 May 2006 19:12:42 -0000 Received: from mta09-winn.ispmail.ntl.com (HELO mtaout03-winn.ispmail.ntl.com) (81.103.221.49) by a.mx.sunsite.dk with SMTP; 10 May 2006 19:12:40 -0000 Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com with ESMTP id <20060510191240.VGLX27969.mtaout03-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Wed, 10 May 2006 20:12:40 +0100 Received: from pwslaptop.csr.com ([81.107.46.246]) by aamtaout02-winn.ispmail.ntl.com with ESMTP id <20060510191240.NVSL24467.aamtaout02-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Wed, 10 May 2006 20:12:40 +0100 Received: from pwslaptop.csr.com (pwslaptop.csr.com [127.0.0.1]) by pwslaptop.csr.com (8.13.6/8.13.4) with ESMTP id k4AJCWrU004708 for ; Wed, 10 May 2006 20:12:34 +0100 Message-Id: <200605101912.k4AJCWrU004708@pwslaptop.csr.com> From: Peter Stephenson To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: no_clobber and error conditions In-Reply-To: Your message of "Wed, 10 May 2006 08:59:02 PDT." <060510085902.ZM11172@torch.brasslantern.com> Date: Wed, 10 May 2006 20:12:32 +0100 Bart Schaefer wrote: > However, it appears that the error from noclobber does not "throw an > exception," it merely causes the command to have exit status 1. > > That's not consistent with csh behavior (tcsh in this sample): > > [schaefer@toltec /tmp]$ ( set noclobber; echo > lockfile; echo oops ) > lockfile: File exists. > [schaefer@toltec /tmp]$ > schaefer[537] ( setopt noclobber; echo > lockfile; echo oops ) > zsh: file exists: lockfile > oops > schaefer[538] It is consistent with bash. The standard just says it "shall fail". I couldn't see a formal definition of "fail", but it seems just to indicate returning a non-zero status, as in If a command fails during word expansion or redirection, its exit status shall be greater than zero. But a failure doesn't need to be atomically handled, does it? How about revisiting: echo >foo || { readonly THROW; THROW= 2>/dev/null; }; (where "readonly THROW" should be at the top of the function). Or, of course, use throw and catch functions: function lock() { emulate -L zsh setopt noclobber xtrace integer ret=-1 autoload -U throw catch while true; do { : >$1 || throw Exists } always { if ! catch Exists; then if catch ''; then ret=1 else ret=0 fi fi } (( ret >= 0 )) && return $ret sleep 1 done } ("return" in the middle of the always block doesn't work. I can't quite make up my mind whether to be embarrassed or not. It depends how seriously you take "Execution [after the always block] continues from the result of the execution of try-list".) -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/