Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glob matching (wildcards) in fish shell not matching bash behavior

Tags:

bash

glob

fish

When I the following command in bash, I get a list of files that match the regular expression I want:

$> ls *-[0-9].jtl
benchmark-1422478133-1.jtl  benchmark-1422502883-4.jtl  benchmark-1422915207-2.jtl

However, when I run the same command in the fish shell, I get different result:

$> ls *-[0-9].jtl
fish: No matches for wildcard '*-[0-9].jtl'.
ls *-[0-9].jtl
   ^

How come?

like image 744
Alan C. Avatar asked Mar 03 '15 17:03

Alan C.


2 Answers

Fish's documentation does not claim to support the full power of POSIX glob patterns.

Quoting the docs:

Wildcards

If a star (*) or a question mark (?) is present in the parameter, fish attempts to match the given parameter to any files in such a way that:

  • ? can match any single character except /.
  • * can match any string of characters not containing /. This includes matching an empty string.
  • ** matches any string of characters. This includes matching an empty string. The string may include the / character but does not need to.

Notably, there's no mention of character classes, as fish doesn't support them.

If you want globs guaranteed to support all POSIX (fnmatch) features, use a POSIX-compliant or POSIX-superset shell.

like image 171
Charles Duffy Avatar answered Oct 20 '22 18:10

Charles Duffy


You can also use more extended tool unix find. It is very powerful.

  • https://kb.iu.edu/d/admm
  • https://duckduckgo.com/?q=unix+find

example: use regular expressions

find . -path '.*-[0-9].jtl' -not -path '.*-32.jtl'
like image 40
kyb Avatar answered Oct 20 '22 18:10

kyb