GNU bug report logs -
#37753
wish for glob(7)-like matcher
Previous Next
Full log
Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):
2019-10-15 12:43:14 +1100, Trent W. Buck:
[...]
> > GNU grep already has options for fixed strings (-F),
> > and BRE, ERE and PCRE. Can we have one for glob(7)?
> >
> > AFAICT nobody has asked for this before; this surprises me,
> > because it "feels" like it should be easy to implement.
> >
> > Am I wrong?
[...]
For the record, ast-open's "grep" has
-K, --ksh-regexp
ksh(1) extended file match patterns.
That's ksh93 wildcards, a superset of bash -O extglob ones
(themselves shaped after ksh88's globs) with same feature level
as regexps.
$ echo abcde | ast-grep -Ko '?c?'
bcd
You can always define a POSIX shell function like:
fnmatch() (
pattern=${1?}; shift
cat -- "$@" | while IFS= read -r line || [ -n "$line" ]; do
case $line in ($pattern) printf '%s\n' "$line"
done
)
(though that will be very slow, especially with shells that
don't have "printf" or "[" builtin; and except in zsh, it won't
work properly with input containing NUL bytes).
Note that there is some variation in wildcard syntax from one
shell to the next and one or from one fnmatch() to the next
(though they generally support the minimum POSIX set at least).
There's also the question of whether you'd want to consider \ as
an escape operator (again YMMV depending on the shell for that
fnmatch() function above).
--
Stephane
This bug report was last modified 5 years and 214 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.