Filename Globs and Text Patterns
A shell glob commonly expands to matching pathnames before a command runs. A text pattern supplied to a program may be interpreted by the program instead.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a filename selection
A shell can expand a pattern like *.csv to a list of existing matching paths. Quoting it may pass the literal characters to the program. Quoting rules establish which interpretation occurs.
Check the no-match case
Shells and options differ on what happens when no pathname matches. Test a directory with none as well as one with several. Distinct boundary tests reveal that difference without assuming the happy path.[1]
Observe glob expansion before the program starts
Entering an unquoted filename glob can let a shell replace it with matching filenames before launching a program. A quoted pattern can instead be delivered to a utility that interprets its own grammar. The same characters can mean different things at those two stages. See shell quoting.
Directory: east.txt, west.txt, east.csv
Unquoted *.txt may become two filename arguments
Quoted "*.txt" may reach the utility as one literal argument
Test no matches and option-looking names
Shells differ when a glob matches nothing. A matched path can also resemble an option. Inspect received arguments and use documented shell settings or explicit enumeration when behavior matters across environments.