Chapter 4

Wildcard Expansion

Wildcards are used in two different ways when writing shell scripts. The shell itself uses wildcards for filename expansion so you can specify a* to match all files starting with the letter a, and *.txt to match all text files. Then there are the more powerful regular expressions used by many shell utilities such as sed, awk, and grep. These use a more formalized language and syntax than the shell, which is more simplistic. The bash shell does offer more powerful wildcard expansion than the standard Bourne shell, and these features are also covered in this chapter.

Also of relevance to regular expressions are the rules that affect quoting and escaping characters of special relevance to the shell. When you need to pass a* to sed, you probably do not want the shell to expand that to match the files in the current directory, but instead pass the wildcard itself directly to sed. The “Quoting” section of this chapter covers the various techniques and special characters necessary to achieve this.

Get Shell Scripting: Expert Recipes for Linux, Bash, and More 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.