GNU Info

Info Node: (bashref.info)Pattern Matching

(bashref.info)Pattern Matching


Up: Filename Expansion
Enter node , (file) or (file)node

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.  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.

`?'
     Matches any single character.

`[...]'
     Matches any one of the enclosed characters.  A pair of characters
     separated by a hyphen denotes a RANGE EXPRESSION; any character
     that sorts between those two characters, inclusive, using the
     current locale's collating sequence and character set, is matched.
     If the first character following the `[' is a `!'  or a `^' then
     any character not enclosed is matched.  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.  The
     sorting order of characters in range expressions is determined by
     the current locale and the value of the `LC_COLLATE' shell
     variable, if set.

     For example, in the default C locale, `[a-dx-z]' is equivalent to
     `[abcdxyz]'.  Many locales sort characters in dictionary order,
     and in these locales `[a-dx-z]' is typically not equivalent to
     `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for
     example.  To obtain the traditional interpretation of ranges in
     bracket expressions, you can force the use of the C locale by
     setting the `LC_COLLATE' or `LC_ALL' environment variable to the
     value `C'.

     Within `[' and `]', CHARACTER CLASSES can be specified using the
     syntax `[:'CLASS`:]', where CLASS is one of the following classes
     defined in the POSIX 1003.2 standard:
          alnum   alpha   ascii   blank   cntrl   digit   graph   lower
          print   punct   space   upper   xdigit

     A character class matches any character belonging to that class.

     Within `[' and `]', an EQUIVALENCE CLASS can be specified using
     the syntax `[='C`=]', which matches all characters with the same
     collation weight (as defined by the current locale) as the
     character C.

     Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
     collating 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 following 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 exactly one of the given patterns.

`!(PATTERN-LIST)'
     Matches anything except one of the given patterns.


automatically generated by info2www version 1.2.2.9