Wildcards
An asterisk (*) – matches one or more occurrences of any character, including no character.
Can anyone explain what is this “ including no character” means?
Wildcards
An asterisk (*) – matches one or more occurrences of any character, including no character.
Can anyone explain what is this “ including no character” means?
Bash's manual phrases it a bit differently (just to pick some source):
*
Matches any string, including the null string
The "null string" is the zero-length string, so the meaning is that *
matches any number of any characters, even none at all. Or, zero or more of any character.
foo*bar
matches e.g.
foo1bar
(where the *
matches one character)foo22bar
(two chars)foobar
, where the *
matches the zero-length string between foo
and bar
.etc.
(Also, *.txt
would also match the filename .txt
, but filenames starting with dots are a special case and don't get matched unless the dot is explicitly given in the pattern, or if something like Bash's dotglob
is set.)
If you want to require at least one character, you can use ?*
since ?
requires and matches exactly one character.
foo*bar
matches the string foobar
, which means that the *
inside that pattern is allowed to match nothing.
– Kusalananda
Jan 20 '24 at 12:20