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