Go to the first, previous, next, last section, table of contents.


Filename Expansion

The final substitution that is applied to command words is filename expansion. This has two stages. Firstly, if the first character of a word is an unquoted percent sign (%) or tilde (~), the following characters up to the first slash are taken to be a users login name and it, together with the leading character is replaced with the login directory for that user. If the user name does not exist, an error message is given and the command is not executed. As a special case, if the user name is empty, the current user is assumed.

Then, if the word contains any unquoted pattern characters, it is replaced by a list of filenames which match the pattern and refer to existent files. The pattern characters are:

`?'
Match any one character.
`*'
Match any string of characters including the empty string.
`[list]'
Match any of the characters in list or, if the first character of list is `^' or `!', any character not in the remainder of the list. For a `]' to appear in the list, it must be first (possibly after the inversion character). A range of characters may be expressed by giving the first and last separated by a hyphen, thus
[A-Za-z]
matches any alphabetic character.

Two exceptions to the above are that the slash separating path components, and a leading period in a path component cannot be matched by a pattern character, they must appear explicitly in the word.

If no file has a name matching the pattern, the pattern is passed to the command as is.

The effect of filename expansion can be modified by giving a value to the shell variable MATCH. If the value of this variable begins with an "N" (for No) then no filename expansion is performed at all. If the value begins with an "E" (for Exact) then if a word contains pattern characters and does not match the name of a file, an error will be given and the command will not be executed.

Filename expansion is also applied to the word given to name a file for I/O redirection. The only difference when applied on this type for word is that an error will be given if a pattern matches more than one file name.


Go to the first, previous, next, last section, table of contents.