Annotation of src/share/man/man7/glob.7, Revision 1.3
1.3 ! uwe 1: .\" $NetBSD: glob.7,v 1.2 2011/01/19 00:21:19 uwe Exp $
1.1 jruoho 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
26: Globbing characters
27: .Pq wildcards
28: are special characters used to perform pattern matching of pathnames and
29: command arguments in the
30: .Xr csh 1 ,
31: .Xr ksh 1 ,
32: and
33: .Xr sh 1
34: shells as well as
35: the C library functions
36: .Xr fnmatch 3
37: and
38: .Xr glob 3 .
39: A glob pattern is a word containing one or more unquoted
40: .Ql \&?
41: or
42: .Ql *
43: characters, or
1.3 ! uwe 44: .Dq Li [..]
1.1 jruoho 45: sequences.
46: .Pp
47: Globs should not be confused with the more powerful
48: regular expressions used by programs such as
49: .Xr grep 1 .
50: While there is some overlap in the special characters used in regular
51: expressions and globs, their meaning is different.
52: .Pp
53: The pattern elements have the following meaning:
54: .Bl -tag -width Ds
1.3 ! uwe 55: .It Li \&?
1.1 jruoho 56: Matches any single character.
1.3 ! uwe 57: .It Li \&*
1.1 jruoho 58: Matches any sequence of zero or more characters.
1.3 ! uwe 59: .It Li [..]
1.1 jruoho 60: Matches any of the characters inside the brackets.
61: Ranges of characters can be specified by separating two characters by a
1.3 ! uwe 62: .Ql \-
1.1 jruoho 63: (e.g.\&
1.3 ! uwe 64: .Dq Li [a0-9]
1.1 jruoho 65: matches the letter
66: .Sq a
67: or any digit).
68: In order to represent itself, a
1.3 ! uwe 69: .Ql \-
1.1 jruoho 70: must either be quoted or the first or last character in the character list.
71: Similarly, a
72: .Ql \&]
73: must be quoted or the first character in the list if it is to represent itself
74: instead of the end of the list.
75: Also, a
76: .Ql \&!
77: appearing at the start of the list has special meaning (see below), so to
78: represent itself it must be quoted or appear later in the list.
79: .Pp
80: Within a bracket expression, the name of a
81: .Em character class
82: enclosed in
1.3 ! uwe 83: .Ql [:
1.1 jruoho 84: and
1.3 ! uwe 85: .Ql :]
1.1 jruoho 86: stands for the list of all characters belonging to that class.
87: Supported character classes:
1.2 uwe 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"
1.1 jruoho 92: .El
93: .Pp
94: These match characters using the macros specified in
95: .Xr ctype 3 .
96: A character class may not be used as an endpoint of a range.
1.3 ! uwe 97: .It Li [!..]
! 98: Like
! 99: .Li [..] ,
1.1 jruoho 100: except it matches any character not inside the brackets.
1.3 ! uwe 101: .It Li \e
1.1 jruoho 102: Matches the character following it verbatim.
103: This is useful to quote the special characters
104: .Ql \&? ,
105: .Ql \&* ,
106: .Ql \&[ ,
107: and
108: .Ql \e
109: such that they lose their special meaning.
110: For example, the pattern
1.3 ! uwe 111: .Dq Li \e\e\e\&*\e[x]\e\&?
1.1 jruoho 112: matches the string
113: .Dq \e\&*[x]\&? .
114: .El
115: .Pp
116: Note that when matching a pathname, the path separator
117: .Ql / ,
118: is not matched by a
119: .Ql \&? ,
120: or
121: .Ql * ,
122: character or by a
1.3 ! uwe 123: .Dq Li [..]
1.1 jruoho 124: sequence.
125: Thus,
126: .Pa /usr/*/*/X11
127: would match
128: .Pa /usr/X11R6/lib/X11
129: and
130: .Pa /usr/X11R6/include/X11
131: while
132: .Pa /usr/*/X11
133: would not match either.
134: Likewise,
135: .Pa /usr/*/bin
136: would match
137: .Pa /usr/local/bin
138: but 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
145: In early versions of
146: .Ux ,
147: the shell did not do pattern expansion itself.
148: A dedicated program,
149: .Pa /etc/glob ,
150: was used to perform the expansion and pass the results to a command.
151: In
152: .At v7 ,
153: with the introduction of the Bourne shell,
154: this functionality was incorporated into the shell itself.
CVSweb <webmaster@jp.NetBSD.org>