File name substitution in the Bourne shell
The Bourne shell permits you to perform file name substitutions.
Command parameters are often file names. You can automatically produce
a list of file names as parameters on a command line. To do this, specify
a character that the shell recognizes as a pattern-matching character. When
a command includes such a character, the shell replaces it with the file names
in a directory.
Note: The Bourne shell does not support file name expansion
based on equivalence classification of characters.
Most characters in such a pattern match themselves, but you can also use some special pattern-matching characters in your pattern. These special characters are as follows:
Item | Description |
---|---|
* | Matches any string, including the null string |
? | Matches any one character |
[ . . . ] | Matches any one of the characters enclosed in square brackets |
[! . . . ] | Matches any character within square brackets other than one of the characters that follow the exclamation mark |
Within square brackets, a pair of characters separated by a hyphen (-
)
specifies the set of all characters lexicographically within the inclusive
range of that pair, according to the binary ordering of character values.
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, *
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 *
, ?
, [
,
or ]
because they can cause infinite recursion (that is,
infinite loops) during pattern-matching attempts.