144 lines
8.5 KiB
Plaintext
144 lines
8.5 KiB
Plaintext
1) ls ./GLOB/gLob *[[:upper:]]
|
||
44patterN patterN paTTerN pAtterN Pattern4
|
||
2) ls -dGLOB/*[[:upper:]]*
|
||
3) ls -d GLOB/?[[:digit:]]*
|
||
4) ls -d GLOB/*[[:digit:]][[:digit:]]*
|
||
|
||
II-
|
||
1)
|
||
Pathname Expansion
|
||
After word splitting, unless the -f option has been set, 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 an alphabetically sorted list of filenames matching the
|
||
pattern (see Pattern Matching below). If no matching filenames are
|
||
found, and the shell option nullglob is not enabled, 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, an error message is printed and the command is not
|
||
executed. If the shell option nocaseglob is enabled, the match is per‐
|
||
formed without regard to the case of alphabetic characters. When a
|
||
pattern is used for pathname expansion, the character ``.'' at the
|
||
start of a name or immediately following a slash must be matched ex‐
|
||
plicitly, unless the shell option dotglob is set. The filenames ``.''
|
||
and ``..'' must always be matched explicitly, even if dotglob is set.
|
||
In other cases, the ``.'' character is not treated specially. When
|
||
matching a pathname, the slash character must always be matched explic‐
|
||
itly by a slash in the pattern, but in other matching contexts it can
|
||
be matched by a special pattern character as described below under Pat‐
|
||
tern Matching. See the description of shopt below under SHELL BUILTIN
|
||
COMMANDS for a description of the nocaseglob, nullglob, failglob, and
|
||
dotglob shell 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 match‐
|
||
ing against the patterns in GLOBIGNORE is performed without regard to
|
||
case. The filenames ``.'' and ``..'' are always ignored when GLOBIG‐
|
||
NORE 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 ``.'' will 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 pattern matching honors the setting of the extglob shell
|
||
option.
|
||
|
||
Pattern Matching
|
||
|
||
Any character that appears in a pattern, other than the special pattern
|
||
characters described below, matches itself. The NUL character may not
|
||
occur in a pattern. A backslash escapes the following character; the
|
||
escaping backslash is discarded when matching. The special pattern
|
||
characters must be quoted if they are to be matched literally.
|
||
|
||
The special pattern characters have the following meanings:
|
||
|
||
* Matches any string, including the null string. When the
|
||
globstar shell option is enabled, and * is used in a
|
||
pathname expansion context, two adjacent *s used as a
|
||
single pattern will match all files and zero or more di‐
|
||
rectories and subdirectories. If followed by a /, two
|
||
adjacent *s will match only directories and subdirecto‐
|
||
ries.
|
||
? Matches any single character.
|
||
[...] Matches any one of the enclosed characters. A pair of
|
||
characters separated by a hyphen denotes a range expres‐
|
||
sion; any character that falls between those two charac‐
|
||
ters, inclusive, using the current locale's collating se‐
|
||
quence and character set, is matched. If the first char‐
|
||
acter following the [ is a ! or a ^ then any character
|
||
not enclosed is matched. The sorting order of characters
|
||
in range expressions is determined by the current locale
|
||
and the values of the LC_COLLATE or LC_ALL shell vari‐
|
||
ables, if set. To obtain the traditional interpretation
|
||
of range expressions, where [a-d] is equivalent to
|
||
[abcd], set value of the LC_ALL shell variable to C, or
|
||
enable the globasciiranges shell option. A - may be
|
||
matched by including it as the first or last character in
|
||
the set. A ] may be matched by including it as the first
|
||
character in the set.
|
||
Within [ and ], character classes can be specified using
|
||
the syntax [:class:], where class is one of the following
|
||
classes defined in the POSIX standard:
|
||
alnum alpha ascii blank cntrl digit graph lower print
|
||
punct space upper word xdigit
|
||
A character class matches any character belonging to that
|
||
class. The word character class matches letters, digits,
|
||
and the character _.
|
||
|
||
Within [ and ], an equivalence class can be specified us‐
|
||
ing the syntax [=c=], which matches all characters with
|
||
the same collation weight (as defined by the current lo‐
|
||
cale) as the character c.
|
||
|
||
Within [ and ], the syntax [.symbol.] matches the collat‐
|
||
ing symbol symbol.
|
||
|
||
If the extglob shell option is enabled using the shopt builtin, several
|
||
extended pattern matching operators are recognized. In the following
|
||
description, a pattern-list is a list of one or more patterns separated
|
||
by a |. Composite patterns may be formed using one or more of the fol‐
|
||
lowing sub-patterns:
|
||
|
||
?(pattern-list)
|
||
Matches zero or one occurrence of the given patterns
|
||
*(pattern-list)
|
||
Matches zero or more occurrences of the given patterns
|
||
+(pattern-list)
|
||
Matches one or more occurrences of the given patterns
|
||
@(pattern-list)
|
||
Matches one of the given patterns
|
||
!(pattern-list)
|
||
Matches anything except one of the given patterns
|
||
|
||
Complicated extended pattern matching against long strings is slow, es‐
|
||
pecially when the patterns contain alternations and the strings contain
|
||
multiple matches. Using separate matches against shorter strings, or
|
||
using arrays of strings instead of a single long string, may be faster.
|
||
|
||
2) shopt Shell option names as accepted by the shopt
|
||
builtin.
|
||
shopt [-pqsu] [-o] [optname ...]
|
||
Toggle the values of settings controlling optional shell behav‐
|
||
ior. The settings can be either those listed below, or, if the
|
||
-o option is used, those available with the -o option to the set
|
||
builtin command. With no options, or with the -p option, a list
|
||
of all settable options is displayed, with an indication of
|
||
whether or not each is set; if optnames are supplied, the output
|
||
is restricted to those options. The -p option causes output to
|
||
be displayed in a form that may be reused as input. Other op‐
|
||
tions have the following meanings:
|
||
-s Enable (set) each optname.
|
||
-u Disable (unset) each optname.
|
||
-q Suppresses normal output (quiet mode); the return status
|
||
indicates whether the optname is set or unset. If multi‐
|
||
ple optname arguments are given with -q, the return sta‐
|
||
tus is zero if all optnames are enabled; non-zero other‐
|
||
wise.
|
||
-o Restricts the values of optname to be those defined for
|
||
the -o option to the set builtin.
|
||
|
||
|
||
|
||
|