rakitzis / rc

rc shell -- independent re-implementation for Unix of the Plan 9 shell (from circa 1992)
Other
250 stars 23 forks source link

Matching empty glob using a literal string is not possible #71

Closed Nomarian closed 1 year ago

Nomarian commented 3 years ago

I do not know if this is a bug or if I'm just stupid. but.

cd /tmp;touch hello.mkv
for (* in *.[mM][Kk][vV] *.[Mm][Pp]4){ ~ $^* '*'.* || echo $* }

should match .[Mm][Pp]4, however it doesn't, there is a workaround, using `~ $ [].` but I find it strange that quoting a * does not yield the correct result. 9rc also suffers from this.

memreflect commented 3 years ago

It works for me as expected, and there is no difference whether I use '*'.* or [*].*.

Here is what happens for me:

  1. *.[mM][Kk][vV] expands to hello.mkv.
  2. hello.mkv does not match the pattern '*'.*, so ~ fails and hello.mkv is printed.
  3. *.[Mm][Pp]4 does not match any file names, so it is not expanded.
  4. *.[Mm][Pp]4 matches the pattern '*'.*, so ~ succeeds (and nothing is printed).
xyb3rt commented 1 year ago

This is not a bug. The provided snippet works as expected just like @memreflect explained.