From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16872 invoked from network); 11 Apr 2005 10:14:13 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Apr 2005 10:14:13 -0000 Received: (qmail 50769 invoked from network); 11 Apr 2005 10:14:08 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Apr 2005 10:14:08 -0000 Received: (qmail 22335 invoked by alias); 11 Apr 2005 10:14:04 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21131 Received: (qmail 22322 invoked from network); 11 Apr 2005 10:14:03 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 11 Apr 2005 10:14:03 -0000 Received: (qmail 50404 invoked from network); 11 Apr 2005 10:14:03 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 11 Apr 2005 10:13:58 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Mon, 11 Apr 2005 11:12:19 +0100 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 11 Apr 2005 11:16:51 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.1/8.12.11) with ESMTP id j3BADx8O022642 for ; Mon, 11 Apr 2005 11:13:59 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.1/8.13.1/Submit) with ESMTP id j3BADwIK022638 for ; Mon, 11 Apr 2005 11:13:59 +0100 Message-Id: <200504111013.j3BADwIK022638@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk Subject: Re: Parse errors don't cause a non-zero exit code? In-reply-to: References: <20050329231719.GH51674@dan.emsphone.com> <200504011208.j31C86Qo018462@news01.csr.com> Date: Mon, 11 Apr 2005 11:13:58 +0100 From: Peter Stephenson X-OriginalArrivalTime: 11 Apr 2005 10:16:51.0636 (UTC) FILETIME=[9418F740:01C53E7F] X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 Felipe Kellermann wrote: > About this issue, I have a long-term question about the exit status of zsh > when it gets passed an script as argument: > > % zsh a > a: can't open input file: a > % print $? > 1 > % a > zsh: command not found: a > % print $? > 127 > % > > I am aware that the standard isn't very clear in this respect, but most > shells explicitly interpret both cases the same way, returning 127 when > the shell gets a command as an argument. Well, it's a script rather than a command, but it looks like other shells don't seem to worry about the distinction here. This is easy to fix. In this case returning status 126 for a file that's not executable doesn't make sense, so I haven't tested for it in the way that's done in other places. I've also modified it so that the error message is a bit more sensible. Before you would get NonExistentScript: can't open input file: NonExistentScript which looks a little silly. Now the first name is the full path to the zsh executable, which also agrees with other shells. Index: Src/init.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/init.c,v retrieving revision 1.50 diff -u -r1.50 init.c --- Src/init.c 1 Apr 2005 10:17:24 -0000 1.50 +++ Src/init.c 11 Apr 2005 10:05:33 -0000 @@ -308,14 +308,14 @@ } if (*argv) { if (unset(SHINSTDIN)) { - argzero = *argv; if (!cmd) - SHIN = movefd(open(unmeta(argzero), O_RDONLY | O_NOCTTY)); + SHIN = movefd(open(unmeta(*argv), O_RDONLY | O_NOCTTY)); if (SHIN == -1) { - zerr("can't open input file: %s", argzero, 0); - exit(1); + zerr("can't open input file: %s", *argv, 0); + exit(127); } opts[INTERACTIVE] &= 1; + argzero = *argv; argv++; } while (*argv) Index: Test/A01grammar.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/A01grammar.ztst,v retrieving revision 1.11 diff -u -r1.11 A01grammar.ztst --- Test/A01grammar.ztst 4 Apr 2005 09:35:43 -0000 1.11 +++ Test/A01grammar.ztst 11 Apr 2005 10:05:33 -0000 @@ -452,3 +452,7 @@ $ZTST_testdir/../Src/zsh -f -c "'" 1:Parse error on inline command causes non-zero exit status ?zsh: unmatched ' + + $ZTST_testdir/../Src/zsh -f NonExistentScript +127q:Non-existent script causes exit status 127 +?$ZTST_testdir/../Src/zsh: can't open input file: NonExistentScript -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************