Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Parse errors don't cause a non-zero exit code?
- X-seq: zsh-workers 21131
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: Parse errors don't cause a non-zero exit code?
- Date: Mon, 11 Apr 2005 11:13:58 +0100
- In-reply-to: <Pine.LNX.4.61.0504082121240.234@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20050329231719.GH51674@xxxxxxxxxxxxxxxx> <200504011208.j31C86Qo018462@xxxxxxxxxxxxxx> <Pine.LNX.4.61.0504082121240.234@xxxxxxxxxxxxxxx>
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@xxxxxxx> 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.
**********************************************************************
Messages sorted by:
Reverse Date,
Date,
Thread,
Author