After word splitting, unless the -f option has been set
(see The Set Builtin), Bash scans each word for the characters
‘*’, ‘?’, and ‘[’.
If one of these characters appears, and is not quoted, then the word is
regarded as a pattern,
and replaced with a sorted list of filenames matching the pattern
(see Pattern Matching),
subject to the value of the GLOBSORT
shell variable
(see Bash Variables).
If no matching filenames are found,
and the shell option nullglob
is disabled, the word is left
unchanged.
If the nullglob
option is set, and no matches are found, the word
is removed.
If the failglob
shell option is set, and no matches are found,
Bash prints an error message and does not execute the command.
If the shell option nocaseglob
is enabled, the match is performed
without regard to the case of alphabetic characters.
When a pattern is used for filename expansion, the character ‘.’
at the start of a filename or immediately following a slash
must be matched explicitly, unless the shell option dotglob
is set.
In order to match the filenames . and ..,
the pattern must begin with ‘.’ (for example, ‘.?’),
even if dotglob
is set.
If the globskipdots
shell option is enabled, the filenames
. and .. never match, even if the pattern begins
with a ‘.’.
When not matching filenames, the ‘.’ character is not treated specially.
When matching a filename, the slash character must always be matched explicitly by a slash in the pattern, but in other matching contexts it can be matched by a special pattern character as described below (see Pattern Matching).
See the description of shopt
in The Shopt Builtin,
for a description of the nocaseglob
, nullglob
,
globskipdots
,
failglob
, and dotglob
options.
The GLOBIGNORE
shell variable may be used to restrict the set of file names matching a
pattern.
If GLOBIGNORE
is set, each matching file name that also matches one of the patterns in
GLOBIGNORE
is removed from the list of matches.
If the nocaseglob
option is set, the matching against the patterns in
GLOBIGNORE
is performed without regard to case.
The filenames
. and ..
are always ignored when GLOBIGNORE
is set and not null.
However, setting GLOBIGNORE
to a non-null value has the effect of enabling the
dotglob
shell option, so all other filenames beginning with a
‘.’
match.
To get the old behavior of ignoring filenames beginning with a
‘.’,
make ‘.*’ one of the patterns in GLOBIGNORE
.
The dotglob
option is disabled when GLOBIGNORE
is unset.
The GLOBIGNORE
pattern matching honors the setting of the extglob
shell
option.
The value of the
GLOBSORT
shell variable controls how the results of pathname expansion are sorted,
as described below (see Bash Variables).