shell - How does "*.txt" regex work with ls command? -
i have file name
atxt
and running command
ls *.txt
ideally should match . 'a' , * 0 character, returning files like
a.txt, b.txt
why here ls treating . literal dot, rater character of regex.
it's called file globbing, not regular expression.
although both back upwards wildcards "?", "*", have different schemes.
for example, "a*" in glob matches filename begins "a", in regex matches string has 0 or more of letter "a". difference wildcard "?" , "*" in regex must have preceding element, while it's unnecessary in globbing.
as lastly question, dot "." has not special meaning in globbing, it's literal dot. match 1 unknown character in globbing, 1 utilize "?".
regex shell unix ls
No comments:
Post a Comment