From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: [BUG] 'test' returns 1 (not >1) on error [was: test is not posix]
Date: Thu, 21 Jan 2016 16:20:54 +0000 [thread overview]
Message-ID: <20160121162054.62baed03@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <56A0D7DE.5000407@inlv.org>
On Thu, 21 Jan 2016 14:06:38 +0100
Martijn Dekker <martijn@inlv.org> wrote:
> Something I also noticed back in May, and which I'm now reminded of, is
> that test/[ returns status 1, and not 2 or higher, if an error occurs.
It's correct inside the condition code, so this is yet another thing the
test builtin needs fixing up for.
diff --git a/Src/builtin.c b/Src/builtin.c
index dd20f9e..98ecb09 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -6531,7 +6531,7 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func)
for (s = argv; *s; s++);
if (s == argv || strcmp(s[-1], "]")) {
zwarnnam(name, "']' expected");
- return 1;
+ return 2;
}
s[-1] = NULL;
}
@@ -6574,19 +6574,19 @@ bin_test(char *name, char **argv, UNUSED(Options ops), int func)
if (errflag) {
errflag &= ~ERRFLAG_ERROR;
zcontext_restore();
- return 1;
+ return 2;
}
if (!prog || tok == LEXERR) {
zwarnnam(name, tokstr ? "parse error" : "argument expected");
zcontext_restore();
- return 1;
+ return 2;
}
zcontext_restore();
if (*curtestarg) {
zwarnnam(name, "too many arguments");
- return 1;
+ return 2;
}
/* syntax is OK, so evaluate */
diff --git a/Test/C02cond.ztst b/Test/C02cond.ztst
index 0b4608a..88cad0d 100644
--- a/Test/C02cond.ztst
+++ b/Test/C02cond.ztst
@@ -223,27 +223,27 @@ F:Failures in these cases do not indicate a problem in the shell.
0:substitution in `[' builtin
[ -n foo scrimble ]
-1:argument checking for [ builtin
+2:argument checking for [ builtin
?(eval):[:1: too many arguments
test -n foo scramble
-1:argument checking for test builtin
+2:argument checking for test builtin
?(eval):test:1: too many arguments
[ -n foo scrimble scromble ]
-1:argument checking for [ builtin
+2:argument checking for [ builtin
?(eval):[:1: too many arguments
test -n foo scramble scrumble
-1:argument checking for test builtin
+2:argument checking for test builtin
?(eval):test:1: too many arguments
[ -n foo -a -n bar scrimble ]
-1:argument checking for [ builtin
+2:argument checking for [ builtin
?(eval):[:1: too many arguments
test -n foo -a -z "" scramble
-1:argument checking for test builtin
+2:argument checking for test builtin
?(eval):test:1: too many arguments
fn() {
prev parent reply other threads:[~2016-01-21 16:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-20 21:06 test is not posix Trek
2016-01-20 21:38 ` Bart Schaefer
2016-01-20 21:44 ` Trek
2016-01-20 23:46 ` Martijn Dekker
2016-01-21 12:41 ` Peter Stephenson
2016-01-21 13:06 ` [BUG] 'test' returns 1 (not >1) on error [was: test is not posix] Martijn Dekker
2016-01-21 16:20 ` 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=20160121162054.62baed03@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-workers@zsh.org \
/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).