Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: *([high]) and nomatch



On Jul 31,  8:41pm, Stephane Chazelas wrote:
}
} I'd have expected:
} 
} zsh -c 'echo *([9999])'
} 
} to fail with a "No match" error if there were fewer than 9999
} non-hidden files in the current directory (and at least 1).

The statment "The syntax is the same as for array subscripts" might
more accurately say "The semantics is the same ..." (or both).  In
concept, this returns an empty match because ${array[9999]} is the
empty string rather than an error when $#array < 9999.

Internally, it returns an empty string because the set of possible
"no matches" conditions (CSH_NULL_GLOB, etc.) has already been tested
before the "subscript" is applied.  Which leads to this somewhat more
surprising side-effect:

torch% print x*
zsh: no matches found: x*
torch% setopt nonomatch
torch% print x*([9999])

torch% print x*([1])   
x*([1])
torch% 

That's easily fixable, the original variation is harder.

While working on this I noticed that glob.c is mixing zalloc, realloc,
and free.  I didn't change that here, but it might need a closer look.

diff --git a/Src/glob.c b/Src/glob.c
index 1e91950..627166c 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -1906,6 +1906,8 @@ zglob(LinkList list, LinkNode np, int nountok)
 		matchptr++;
 	    }
 	}
+    } else if (!badcshglob && !isset(NOMATCH) && matchct == 1) {
+	insert_glob_match(list, node, (--matchptr)->name);
     }
     free(matchbuf);
 



Messages sorted by: Reverse Date, Date, Thread, Author