xref: /netbsd/share/man/man7/glob.7 (revision 6550d01e)
1.\" $NetBSD: glob.7,v 1.3 2011/01/19 00:33:10 uwe Exp $
2.\"
3.\"	$OpenBSD: glob.7,v 1.3 2009/12/26 15:24:54 schwarze Exp $
4.\"
5.\" Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
6.\"
7.\" Permission to use, copy, modify, and distribute this software for any
8.\" purpose with or without fee is hereby granted, provided that the above
9.\" copyright notice and this permission notice appear in all copies.
10.\"
11.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18.\"
19.Dd November 30, 2010
20.Dt GLOB 7
21.Os
22.Sh NAME
23.Nm glob
24.Nd shell-style pattern matching
25.Sh DESCRIPTION
26Globbing characters
27.Pq wildcards
28are special characters used to perform pattern matching of pathnames and
29command arguments in the
30.Xr csh 1 ,
31.Xr ksh 1 ,
32and
33.Xr sh 1
34shells as well as
35the C library functions
36.Xr fnmatch 3
37and
38.Xr glob 3 .
39A glob pattern is a word containing one or more unquoted
40.Ql \&?
41or
42.Ql *
43characters, or
44.Dq Li [..]
45sequences.
46.Pp
47Globs should not be confused with the more powerful
48regular expressions used by programs such as
49.Xr grep 1 .
50While there is some overlap in the special characters used in regular
51expressions and globs, their meaning is different.
52.Pp
53The pattern elements have the following meaning:
54.Bl -tag -width Ds
55.It Li \&?
56Matches any single character.
57.It Li \&*
58Matches any sequence of zero or more characters.
59.It Li [..]
60Matches any of the characters inside the brackets.
61Ranges of characters can be specified by separating two characters by a
62.Ql \-
63(e.g.\&
64.Dq Li [a0-9]
65matches the letter
66.Sq a
67or any digit).
68In order to represent itself, a
69.Ql \-
70must either be quoted or the first or last character in the character list.
71Similarly, a
72.Ql \&]
73must be quoted or the first character in the list if it is to represent itself
74instead of the end of the list.
75Also, a
76.Ql \&!
77appearing at the start of the list has special meaning (see below), so to
78represent itself it must be quoted or appear later in the list.
79.Pp
80Within a bracket expression, the name of a
81.Em character class
82enclosed in
83.Ql [:
84and
85.Ql :]
86stands for the list of all characters belonging to that class.
87Supported character classes:
88.Bl -column ".Li xdigit" ".Li xdigit" ".Li xdigit" -offset indent
89.It Li "alnum" Ta Li "cntrl" Ta Li "lower" Ta Li "space"
90.It Li "alpha" Ta Li "digit" Ta Li "print" Ta Li "upper"
91.It Li "blank" Ta Li "graph" Ta Li "punct" Ta Li "xdigit"
92.El
93.Pp
94These match characters using the macros specified in
95.Xr ctype 3 .
96A character class may not be used as an endpoint of a range.
97.It Li [!..]
98Like
99.Li [..] ,
100except it matches any character not inside the brackets.
101.It Li \e
102Matches the character following it verbatim.
103This is useful to quote the special characters
104.Ql \&? ,
105.Ql \&* ,
106.Ql \&[ ,
107and
108.Ql \e
109such that they lose their special meaning.
110For example, the pattern
111.Dq Li \e\e\e\&*\e[x]\e\&?
112matches the string
113.Dq \e\&*[x]\&? .
114.El
115.Pp
116Note that when matching a pathname, the path separator
117.Ql / ,
118is not matched by a
119.Ql \&? ,
120or
121.Ql * ,
122character or by a
123.Dq Li [..]
124sequence.
125Thus,
126.Pa /usr/*/*/X11
127would match
128.Pa /usr/X11R6/lib/X11
129and
130.Pa /usr/X11R6/include/X11
131while
132.Pa /usr/*/X11
133would not match either.
134Likewise,
135.Pa /usr/*/bin
136would match
137.Pa /usr/local/bin
138but not
139.Pa /usr/bin .
140.Sh SEE ALSO
141.Xr fnmatch 3 ,
142.Xr glob 3 ,
143.Xr re_format 7
144.Sh HISTORY
145In early versions of
146.Ux ,
147the shell did not do pattern expansion itself.
148A dedicated program,
149.Pa /etc/glob ,
150was used to perform the expansion and pass the results to a command.
151In
152.At v7 ,
153with the introduction of the Bourne shell,
154this functionality was incorporated into the shell itself.
155