xref: /netbsd-src/share/man/man7/glob.7 (revision b184d46aae59c6cbd73d94389cabdf066648e371)
1*b184d46aSabs.\" $NetBSD: glob.7,v 1.4 2021/11/02 22:13:14 abs Exp $
2d34231afSjruoho.\"
3d34231afSjruoho.\"	$OpenBSD: glob.7,v 1.3 2009/12/26 15:24:54 schwarze Exp $
4d34231afSjruoho.\"
5d34231afSjruoho.\" Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
6d34231afSjruoho.\"
7d34231afSjruoho.\" Permission to use, copy, modify, and distribute this software for any
8d34231afSjruoho.\" purpose with or without fee is hereby granted, provided that the above
9d34231afSjruoho.\" copyright notice and this permission notice appear in all copies.
10d34231afSjruoho.\"
11d34231afSjruoho.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12d34231afSjruoho.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13d34231afSjruoho.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14d34231afSjruoho.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15d34231afSjruoho.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16d34231afSjruoho.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17d34231afSjruoho.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18d34231afSjruoho.\"
19*b184d46aSabs.Dd November 2, 2021
20d34231afSjruoho.Dt GLOB 7
21d34231afSjruoho.Os
22d34231afSjruoho.Sh NAME
23d34231afSjruoho.Nm glob
24d34231afSjruoho.Nd shell-style pattern matching
25d34231afSjruoho.Sh DESCRIPTION
26d34231afSjruohoGlobbing characters
27d34231afSjruoho.Pq wildcards
28d34231afSjruohoare special characters used to perform pattern matching of pathnames and
29d34231afSjruohocommand arguments in the
30d34231afSjruoho.Xr csh 1 ,
31d34231afSjruoho.Xr ksh 1 ,
32d34231afSjruohoand
33d34231afSjruoho.Xr sh 1
34d34231afSjruohoshells as well as
35d34231afSjruohothe C library functions
36d34231afSjruoho.Xr fnmatch 3
37d34231afSjruohoand
38d34231afSjruoho.Xr glob 3 .
39d34231afSjruohoA glob pattern is a word containing one or more unquoted
40d34231afSjruoho.Ql \&?
41d34231afSjruohoor
42d34231afSjruoho.Ql *
43d34231afSjruohocharacters, or
447ec5ba54Suwe.Dq Li [..]
45d34231afSjruohosequences.
46d34231afSjruoho.Pp
47d34231afSjruohoGlobs should not be confused with the more powerful
48d34231afSjruohoregular expressions used by programs such as
49d34231afSjruoho.Xr grep 1 .
50d34231afSjruohoWhile there is some overlap in the special characters used in regular
51d34231afSjruohoexpressions and globs, their meaning is different.
52d34231afSjruoho.Pp
53d34231afSjruohoThe pattern elements have the following meaning:
54d34231afSjruoho.Bl -tag -width Ds
557ec5ba54Suwe.It Li \&?
56d34231afSjruohoMatches any single character.
577ec5ba54Suwe.It Li \&*
58d34231afSjruohoMatches any sequence of zero or more characters.
597ec5ba54Suwe.It Li [..]
60d34231afSjruohoMatches any of the characters inside the brackets.
61d34231afSjruohoRanges of characters can be specified by separating two characters by a
627ec5ba54Suwe.Ql \-
63d34231afSjruoho(e.g.\&
647ec5ba54Suwe.Dq Li [a0-9]
65d34231afSjruohomatches the letter
66d34231afSjruoho.Sq a
67d34231afSjruohoor any digit).
68d34231afSjruohoIn order to represent itself, a
697ec5ba54Suwe.Ql \-
70d34231afSjruohomust either be quoted or the first or last character in the character list.
71d34231afSjruohoSimilarly, a
72d34231afSjruoho.Ql \&]
73d34231afSjruohomust be quoted or the first character in the list if it is to represent itself
74d34231afSjruohoinstead of the end of the list.
75d34231afSjruohoAlso, a
76d34231afSjruoho.Ql \&!
77d34231afSjruohoappearing at the start of the list has special meaning (see below), so to
78d34231afSjruohorepresent itself it must be quoted or appear later in the list.
79d34231afSjruoho.Pp
80d34231afSjruohoWithin a bracket expression, the name of a
81d34231afSjruoho.Em character class
82d34231afSjruohoenclosed in
837ec5ba54Suwe.Ql [:
84d34231afSjruohoand
857ec5ba54Suwe.Ql :]
86d34231afSjruohostands for the list of all characters belonging to that class.
87d34231afSjruohoSupported character classes:
88cc6916d6Suwe.Bl -column ".Li xdigit" ".Li xdigit" ".Li xdigit" -offset indent
89cc6916d6Suwe.It Li "alnum" Ta Li "cntrl" Ta Li "lower" Ta Li "space"
90cc6916d6Suwe.It Li "alpha" Ta Li "digit" Ta Li "print" Ta Li "upper"
91cc6916d6Suwe.It Li "blank" Ta Li "graph" Ta Li "punct" Ta Li "xdigit"
92d34231afSjruoho.El
93d34231afSjruoho.Pp
94d34231afSjruohoThese match characters using the macros specified in
95d34231afSjruoho.Xr ctype 3 .
96d34231afSjruohoA character class may not be used as an endpoint of a range.
977ec5ba54Suwe.It Li [!..]
987ec5ba54SuweLike
997ec5ba54Suwe.Li [..] ,
100d34231afSjruohoexcept it matches any character not inside the brackets.
1017ec5ba54Suwe.It Li \e
102d34231afSjruohoMatches the character following it verbatim.
103d34231afSjruohoThis is useful to quote the special characters
104d34231afSjruoho.Ql \&? ,
105d34231afSjruoho.Ql \&* ,
106d34231afSjruoho.Ql \&[ ,
107d34231afSjruohoand
108d34231afSjruoho.Ql \e
109d34231afSjruohosuch that they lose their special meaning.
110d34231afSjruohoFor example, the pattern
1117ec5ba54Suwe.Dq Li \e\e\e\&*\e[x]\e\&?
112d34231afSjruohomatches the string
113d34231afSjruoho.Dq \e\&*[x]\&? .
114d34231afSjruoho.El
115d34231afSjruoho.Pp
116d34231afSjruohoNote that when matching a pathname, the path separator
117d34231afSjruoho.Ql / ,
118d34231afSjruohois not matched by a
119d34231afSjruoho.Ql \&? ,
120d34231afSjruohoor
121d34231afSjruoho.Ql * ,
122d34231afSjruohocharacter or by a
1237ec5ba54Suwe.Dq Li [..]
124d34231afSjruohosequence.
125d34231afSjruohoThus,
126d34231afSjruoho.Pa /usr/*/*/X11
127d34231afSjruohowould match
128*b184d46aSabs.Pa /usr/X11R7/lib/X11
129d34231afSjruohoand
130*b184d46aSabs.Pa /usr/X11R7/include/X11
131d34231afSjruohowhile
132d34231afSjruoho.Pa /usr/*/X11
133d34231afSjruohowould not match either.
134d34231afSjruohoLikewise,
135d34231afSjruoho.Pa /usr/*/bin
136d34231afSjruohowould match
137d34231afSjruoho.Pa /usr/local/bin
138d34231afSjruohobut not
139d34231afSjruoho.Pa /usr/bin .
140d34231afSjruoho.Sh SEE ALSO
141d34231afSjruoho.Xr fnmatch 3 ,
142d34231afSjruoho.Xr glob 3 ,
143d34231afSjruoho.Xr re_format 7
144d34231afSjruoho.Sh HISTORY
145d34231afSjruohoIn early versions of
146d34231afSjruoho.Ux ,
147d34231afSjruohothe shell did not do pattern expansion itself.
148d34231afSjruohoA dedicated program,
149d34231afSjruoho.Pa /etc/glob ,
150d34231afSjruohowas used to perform the expansion and pass the results to a command.
151d34231afSjruohoIn
152d34231afSjruoho.At v7 ,
153d34231afSjruohowith the introduction of the Bourne shell,
154d34231afSjruohothis functionality was incorporated into the shell itself.
155