glob − output pathnames matching a pattern
On the command−line:
glob 'eenie{meenie,mynie,moe}*.[ch]'
When this program was originally created, *perl* did not have a builtin "glob" feature and would rely on the *csh* to do the work for it. With Perl v5.6 in March 2000, the File::Glob module has done that work without interacting with *csh*.
The expressions that are passed as arguments to glob must adhere to csh/tcsh pattern−matching syntax for wildcard filename expansion (also known as globbing). Unquoted words containing an asterisk ("*"), question−mark ("?"), square−brackets ("[...]"), or curly−braces ("{...}"), or beginning with a tilde (˜), are expanded into an alphabetically sorted list of filenames, as follows:
|
"*" |
Match any (zero or more) characters. |
|||
|
"?" |
Match any single character. |
[...]
Match any single character in the given character class. The character class is the enclosed list(s) or range(s). A list is a string of characters. A range is two characters separated by a dash (−), and includes all the characters in between the two characters given (inclusive). If a dash ("−") is intended to be part of the character class it must be the first character given.
{str1,str2,...}
Expand the given "word−set" to each string (or filename−matching pattern) in the comma−separated list. Unlike the pattern−matching expressions above, the expansion of this construct is not sorted. For instance, "{foo,bar}" expands to "foo bar" (not "bar foo"). As special cases, unmatched "{" and "}", and the "empty set" (the string {}) are treated as ordinary characters instead of pattern−matching meta−characters. A backslash ("\)" may be used to escape an opening or closing curly brace, or the backslash character itself. Note that word−sets may be nested!
|
"˜" |
The home directory of the invoking user as indicated by the value of the variable $HOME. |
˜username
The home directory of the user whose login name is 'username', as indicated by the password entry for the named user.
Only the patterns *, ? and [...] imply pattern matching; an error results if no filename matches a pattern that contains them. When a period or "dot" (.) is the first character in a filename or pathname component, it must be matched explicitly. The filename component separator character (e.g., / or slash) must also be matched explicitly.
When the first argument is −0 (a minus sign followed by the number zero), then a NUL character ("\0") is used to separate the expanded words and/or filenames when printing them to standard output. Otherwise a newline is used as the word/filename output separator.
When glob is invoked as a script from the command−line, the exit−status returned will be 0 if any files were matched or word−sets were expanded; 1 if no files/word−sets were matched/expanded; and 2 if some other kind of error occurred.
If no filenames are matched and pattern−matching characters were used ("*", "?", or "[...]"), then an error message of "No Match" is issued. If a user's home directory is specified using tilde−expansion (e.g., "˜username") but the corresponding username or their home directory cannot be found, then the error message "Unknown user: username" is issued.
Copyright (c) 1997−2025 Marc Mengel. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Marc Mengel <[email protected]>
brian f foy <[email protected]> − v2.1 February 2025
Reimplement this as a thin layer over File::Glob::csh_glob. This program was written before that was a core module, but had several edge cases where it would crash.
Brad Appleton <[email protected]> − v1.2 March 1999
Modified to use qr// (and some other minor speedups), to explode subexpressions in curly braces (a la csh −− rather than using just plain alternation), and made callable as a standalone script.