Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [ -f glob ]
- X-seq: zsh-users 12412
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: [ -f glob ]
- Date: Thu, 10 Jan 2008 12:06:57 +0000
- In-reply-to: <200801100958.m0A9w2jj015161@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <20080109091335.49226.qmail@xxxxxxxxxxx> <200801091239.m09CdmR9003125@xxxxxxxxxxxxxx> <20080110044842.63406.qmail@xxxxxxxxxxx> <200801100958.m0A9w2jj015161@xxxxxxxxxxxxxx>
On Thu, 10 Jan 2008 09:58:02 +0000
Peter Stephenson <pws@xxxxxxx> wrote:
> Atom Smasher wrote:
> > On Wed, 9 Jan 2008, Peter Stephenson wrote:
> >
> > > This is broken: -f expectes exactly one argument and you're giving it an
> > > expression that expands to multiple arguments.
> > ================
> >
> > but, why would it work on bsd and not work on solaris?
>
> You're into implementation-specific land, from whose Bourne shell no
> traveller returns.
However, zsh isn't helping by not reporting an error if there are arguments
it couldn't parse.
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.184
diff -u -r1.184 builtin.c
--- Src/builtin.c 17 Dec 2007 17:11:29 -0000 1.184
+++ Src/builtin.c 10 Jan 2008 12:04:28 -0000
@@ -5472,7 +5472,7 @@
/* holds arguments for testlex() */
/**/
-char **testargs;
+char **testargs, **curtestarg;
/* test, [: the old-style general purpose logical expression builtin */
@@ -5483,7 +5483,7 @@
if (tok == LEXERR)
return;
- tokstr = *testargs;
+ tokstr = *(curtestarg = testargs);
if (!*testargs) {
/* if tok is already zero, reading past the end: error */
tok = tok ? NULLTOK : LEXERR;
@@ -5557,6 +5557,11 @@
return 1;
}
+ if (*curtestarg) {
+ zwarnnam(name, "too many arguments");
+ return 1;
+ }
+
/* syntax is OK, so evaluate */
state.prog = prog;
Index: Src/parse.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/parse.c,v
retrieving revision 1.67
diff -u -r1.67 parse.c
--- Src/parse.c 27 Jun 2007 13:56:11 -0000 1.67
+++ Src/parse.c 10 Jan 2008 12:04:32 -0000
@@ -537,6 +537,12 @@
return bld_eprog();
}
+/*
+ * This entry point is only used for bin_test, our attempt to
+ * provide compatibility with /bin/[ and /bin/test. Hence
+ * at this point condlex should always be set to testlex.
+ */
+
/**/
mod_export Eprog
parse_cond(void)
Index: Test/C02cond.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/C02cond.ztst,v
retrieving revision 1.20
diff -u -r1.20 C02cond.ztst
--- Test/C02cond.ztst 4 Jan 2008 14:45:40 -0000 1.20
+++ Test/C02cond.ztst 10 Jan 2008 12:04:33 -0000
@@ -199,7 +199,31 @@
0:strings with `[' builtin
[ `echo 0` -lt `echo 1` ]
-0:substituion in `[' builtin
+0:substitution in `[' builtin
+
+ [ -n foo scrimble ]
+1:argument checking for [ builtin
+?(eval):[:1: too many arguments
+
+ test -n foo scramble
+1:argument checking for test builtin
+?(eval):test:1: too many arguments
+
+ [ -n foo scrimble scromble ]
+1:argument checking for [ builtin
+?(eval):[:1: too many arguments
+
+ test -n foo scramble scrumble
+1:argument checking for test builtin
+?(eval):test:1: too many arguments
+
+ [ -n foo -a -n bar scrimble ]
+1:argument checking for [ builtin
+?(eval):[:1: too many arguments
+
+ test -n foo -a -z "" scramble
+1:argument checking for test builtin
+?(eval):test:1: too many arguments
fn() {
# careful: first file must exist to trigger bug
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author