From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: Parse errors don't cause a non-zero exit code?
Date: Mon, 11 Apr 2005 11:13:58 +0100 [thread overview]
Message-ID: <200504111013.j3BADwIK022638@news01.csr.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0504082121240.234@nyvra.alien.bet>
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 <pws@csr.com> 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.
**********************************************************************
prev parent reply other threads:[~2005-04-11 10:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-29 23:17 Dan Nelson
2005-03-31 17:14 ` Dan Nelson
2005-04-01 10:07 ` Peter Stephenson
2005-04-01 20:06 ` Dan Nelson
2005-04-01 12:08 ` Peter Stephenson
2005-04-09 0:50 ` Felipe Kellermann
2005-04-11 10:13 ` Peter Stephenson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200504111013.j3BADwIK022638@news01.csr.com \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).