bash - Glob pattern to match non-hidden filenames that don't start with a particular string -
i'm pretty inexperienced globbing in general. how 1 go writing glob pattern matches filenames not starting with, say, "ab" still need length of @ least 2? i.e. "start 2-letter string other "ab"" homework question, , basic bash globs allowed, , must work "echo <glob here>".
note: question verbatim
(non-hidden) files in current directory names contain @ least 2 characters, not start ab.
printed on paper. i'm pretty sure didn't misunderstand anything. requirements are
for each of following file search criteria, provide globbing pattern matches criterion. answer in each case should text file following format:
echo <pattern>
my current attempt echo {a[!b]*,[!a.]?*}
somehow gets no points automatic grader runs file against test case automatically without human intervention.
for single letter, do:
$ echo [!a]?*
however, 2 letters (and assuming files can start numbers or punctuation or kinds of other things), can think of without resorting shopt
:
$ globignore=ab* $ echo *
well, now, technically, work:
$ echo [!a]?* [a][!b]*
but leave nasty [a][!b]*
in our results if there no files starting a
+1 or more characters, not undesirable, considered bug in application, on grounds not consider valid answer. omit [a][!b]*
, have resort nullglob
(and if extglob
isn't allowed, nullglob
isn't either):
$ shopt -s nullglob $ echo [!a]?* [a][!b]*
fwiw, extglob
be:
$ shopt -s extglob
$ echo !(ab*) previous answer match files less 2 characters, @perreal says:
$ @([^a]?|?[^b])*
Comments
Post a Comment