The Korn shell, or POSIX shell, performs file name substitution by scanning each command word specified by the Word variable for certain characters. If a command word includes the * (asterisk), ? (question mark) or [ (left bracket) characters, and the -f flag has not been set, the shell regards the word as a pattern. The shell replaces the word with file names, sorted according to the collating sequence in effect in the current locale, that match that pattern. If the shell does not find a file name to match the pattern, it does not change the word.
When the shell uses a pattern for file name substitution, the . (dot) and / (slash) characters must be matched explicitly.
Note: The Korn shell does not treat these characters specially in other instances of pattern matching.
These pattern-matching characters indicate the following substitutions:
You can also use the [:charclass:] notation to match file names within a range indication. This format instructs the system to match any single character belonging to class. The definition of which characters constitute a specific character class is present through the LC_CTYPE category of the setlocale subroutine. All character classes specified in the current locale are recognized.
The names of some of the character classes are:
For example, [[:upper:]] matches any uppercase letter.
The Korn shell supports file name expansion based on collating elements or symbols, or equivalence classes.
A PatternList is a list of one or more patterns separated from each other with a vertical bar ( | ). Composite patterns are formed with one or more of the following:
Pattern matching has some restrictions. If the first character of a file name is a . (dot), it can be matched only by a pattern that also begins with a dot. For example, * (asterisk) matches the file names myfile and yourfile but not the file names .myfile and .yourfile. To match these files, use a pattern such as the following:
.*file
If a pattern does not match any file names, then the pattern itself is returned as the result of the attempted match.
File and directory names should not contain the characters * (asterisk), ? (question mark), [ (left bracket), or ] (right bracket) because they can cause infinite recursion (that is, infinite loops) during pattern-matching attempts.
The quote characters, backslash (\), single quote ('), and double quote (") that were present in the original word will be removed unless they have themselves been quoted.