Pattern Matching and Regular Expressions

This section describes the meta-characters and rules for filename expansion, pattern matching for the case statement, and regular expressions.

Filename Expansion and Pattern Matching

The rules for filename expansion are as follows:

  • Any word on the command line that contains a meta-character is expanded to a list of files that match the pattern word.

  • If no filename matches are found, the pattern word is not substituted.

  • Meta-characters cannot match a leading period or a slash.

The filename expansion meta-characters are

* matches 0 or more of any character
? matches exactly 1 of any character
[list] matches exactly 1 of any character in list
[!list] matches exactly 1 of any character not in list

Limited Regular ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.