A wildcard is part of a glob pattern. At their simplest *
and ?
are wildcards that are also glob patterns. Here are some simple globs:
*.sh # could match "fred.sh" and also ".sh"
matchme # would match "matchme"
file[0-9]*.txt # could match "file12.txt" but also "file12yz.txt"
?ile # could match "mile" or "file" but not "smile"
The glob patterns you have listed in your question are extended glob patterns. For bash
they are active in [[ "$var" == {pattern} ]]
constructs but are only available for filename matching if extglob
is enabled:
shopt -s extglob # Enable extended globs (bash)
ls -d +([[:digit:]]) # List files/directories whose names are just digits
From what I see, the search pattern *.sh
does not include a metacharacter to match any character after *
The pattern *.sh
uses a wildcard *
that will match zero or more characters. Remember that globs are not Regular Expressions (ordinary or Extended), but these are equivalent:
Glob RE Description
.sh ^..sh$ Match anything ending with the three characters ".sh"
?ile ^.ile$ Match any single character then the text "ile"
+([[:digit:]]) ^[[:digit:]]+$ Match one or more digits (potentially any alphabet, not just 0-9)
Extended Glob ERE Description
@(one|two) ^(one|two)$ Match either "one" or "two"
Note that an ordinary RE to match "one" or "two" would need to mark out the brackets and separator, i.e. ^\(one\|two\)$
, as they are not included. In contrast an Extended Regular Expression does include these operators, i.e. ^(one|two)$
wildcard
is aShell Glob
. Which suggests that use of*.sh
is a different variation of Glob Matching that does not require the introduction of a metacharacter to explicitly stateany character
(as is done with regex using the.
metacharacter). – Vera Jan 29 '23 at 21:22