9330 stack overflow when creating a deeply nested dataset
[unleashed.git] / usr / src / man / man5 / fnmatch.5
blob79649713b4aa01918e39a35e798616713986e104
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
44 .\" Portions Copyright (c) 1995, Sun Microsystems, Inc.  All Rights Reserved.
45 .\"
46 .TH FNMATCH 5 "Jun 14, 2015"
47 .SH NAME
48 fnmatch \- file name pattern matching
49 .SH DESCRIPTION
50 .LP
51 The pattern matching notation described below  is used to specify patterns for
52 matching strings in the shell. Historically, pattern matching notation is
53 related to, but slightly different from, the regular expression notation. For
54 this reason, the description of the rules for this pattern matching notation is
55 based on the description of regular expression notation described on the
56 \fBregex\fR(5) manual page.
57 .SS "Patterns Matching a Single Character"
58 .LP
59 The following patterns match a single character: \fIordinary characters\fR,
60 \fIspecial pattern characters\fR and \fIpattern bracket expressions\fR. The pattern
61 bracket expression will also match a single collating element.
62 .sp
63 .LP
64 An ordinary character is a pattern that matches itself. It can be any character
65 in the supported character set except for \fINUL\fR, those special shell
66 characters that require quoting, and the following three special pattern
67 characters. Matching is based on the bit pattern used for encoding the
68 character, not on the graphic representation of the character. If any character
69 (ordinary, shell special, or pattern special) is quoted, that pattern will
70 match the character itself. The shell special characters always require
71 quoting.
72 .sp
73 .LP
74 When unquoted and outside a bracket expression, the following three characters
75 will have special meaning in the specification of patterns:
76 .sp
77 .ne 2
78 .na
79 \fB\fB?\fR \fR
80 .ad
81 .RS 6n
82 A question-mark is a pattern that will match any character.
83 .RE
85 .sp
86 .ne 2
87 .na
88 \fB\fB*\fR \fR
89 .ad
90 .RS 6n
91 An asterisk is a pattern that will match multiple characters, as described in
92 \fBPatterns Matching Multiple Characters\fR, below.
93 .RE
95 .sp
96 .ne 2
97 .na
98 \fB\fB[\fR \fR
99 .ad
100 .RS 6n
101 The open bracket will introduce a pattern bracket expression.
106 The description of basic regular expression bracket expressions on the
107 \fBregex\fR(5) manual page also applies to the pattern bracket expression,
108 except that the exclamation-mark character \fB(\fR \fB!\fR \fB)\fR replaces the
109 circumflex character (\fB^\fR) in its role in a \fInon-matching list\fR in the
110 regular expression notation. A bracket expression starting with an unquoted
111 circumflex character produces unspecified results.
114 The restriction on a circumflex in a bracket expression is to allow
115 implementations that support pattern matching using the circumflex as the
116 negation character in addition to the exclamation-mark. A portable application
117 must use something like \fB[\e^!\fR] to match either character.
120 When pattern matching is used where shell quote removal is not performed (such
121 as in the argument to the \fBfind\fR \fB-name\fR primary when \fBfind\fR is
122 being called using one of the  \fBexec\fR functions, or in the \fIpattern\fR
123 argument to the \fBfnmatch\fR(3C) function, special characters can be escaped
124 to remove their special meaning by preceding them with a backslash character.
125 This escaping backslash will be discarded. The sequence \fB\e\e\fR represents
126 one literal backslash. All of the requirements and effects of quoting on
127 ordinary, shell special and special pattern characters will apply to escaping
128 in this context.
131 Both quoting and escaping are described here because pattern matching must work
132 in three separate circumstances:
133 .RS +4
135 .ie t \(bu
136 .el o
137 Calling directly upon the shell, such as in pathname expansion or in a
138 \fBcase\fR statement. All of the following will match the string or file
139 \fBabc\fR:
144 l l l l l
145 l l l l l .
146 \fBabc\fR       \fB"abc"\fR     \fBa"b"c\fR     \fBa\ebc\fR     \fBa[b]c\fR
147 \fBa["b"]c\fR   \fBa[\eb]c\fR   \fBa["\eb"]c\fR \fBa?c\fR       \fBa*c\fR
150 The following will not:
155 l l l .
156 \fB"a?c"\fR     \fBa\e*c\fR     \fBa\e[b]c\fR
160 .RS +4
162 .ie t \(bu
163 .el o
164 Calling a utility or function without going through a shell, as described for
165 \fBfind\fR(1) and the function \fBfnmatch\fR(3C)
167 .RS +4
169 .ie t \(bu
170 .el o
171 Calling utilities such as \fBfind\fR, \fBcpio\fR, \fBtar\fR or \fBpax\fR
172 through the shell command line. In this case, shell quote removal is performed
173 before the utility sees the argument.  For example, in:
175 find /bin -name e\ec[\eh]o -print
177 after quote removal, the backslashes are presented to \fBfind\fR and it treats
178 them as escape characters. Both precede ordinary characters, so the \fBc\fR and
179 \fBh\fR represent themselves and \fBecho\fR would be found on many historical
180 systems (that have it in \fB/bin\fR). To find a file name that contained shell
181 special characters or pattern characters, both quoting and escaping are
182 required, such as:
184 \fBpax -r .\|.\|. "*a\e\|(\|\e?"\fR
186 to extract a filename ending with \fBa(?\fR.
190 Conforming applications are required to quote or escape the shell special
191 characters (sometimes called metacharacters). If used without this protection,
192 syntax errors can result or implementation extensions can be triggered. For
193 example, the KornShell supports a series of extensions based on parentheses in
194 patterns; see  \fBksh\fR(1)
195 .SS "Patterns Matching Multiple Characters"
197 The following rules are used to construct \fIpatterns matching multiple
198 characters\fR from \fIpatterns matching a single character\fR:
199 .RS +4
201 .ie t \(bu
202 .el o
203 The asterisk (*) is a pattern that will match any string, including the null
204 string.
206 .RS +4
208 .ie t \(bu
209 .el o
210 The concatenation of \fIpatterns matching a single character\fR is a valid
211 pattern that will match the concatenation of the single characters or collating
212 elements matched by each of the concatenated patterns.
214 .RS +4
216 .ie t \(bu
217 .el o
218 The concatenation of one or more \fIpatterns matching a single character\fR
219 with one or more asterisks is a valid pattern. In such patterns, each asterisk
220 will match a string of zero or more characters, matching the greatest possible
221 number of characters that still allows the remainder of the pattern to match
222 the string.
226 Since each asterisk matches zero or more occurrences, the patterns \fBa*b\fR
227 and  \fBa**b\fR have identical functionality.
230 Examples:
232 .ne 2
234 \fB\fBa[bc]\fR \fR
236 .RS 10n
237 matches the strings \fBab\fR and \fBac\fR.
241 .ne 2
243 \fB\fBa*d\fR \fR
245 .RS 10n
246 matches the strings \fBad\fR, \fBabd\fR and \fBabcd\fR, but not the string
247 \fBabc\fR.
251 .ne 2
253 \fB\fBa*d*\fR \fR
255 .RS 10n
256 matches the strings \fBad\fR, \fBabcd\fR, \fBabcdef\fR, \fBaaaad\fR and
257 \fBadddd\fR.
261 .ne 2
263 \fB\fB*a*d\fR \fR
265 .RS 10n
266 matches the strings \fBad\fR, \fBabcd\fR, \fBefabcd\fR, \fBaaaad\fR and
267 \fBadddd\fR.
270 .SS "Patterns Used for Filename Expansion"
272 The rules described so far in \fBPatterns\fR \fBMatching\fR \fBMultiple\fR
273 \fBCharacters\fR and \fBPatterns\fR \fBMatching\fR \fBa\fR \fBSingle\fR
274 \fBCharacter\fR are qualified by the following rules that apply when pattern
275 matching notation is used for filename expansion.
276 .RS +4
279 The slash character in a pathname must be explicitly matched by using one
280 or more slashes in the pattern; it cannot be matched by the asterisk or
281 question-mark special characters or by a bracket expression. Slashes in the
282 pattern are identified before bracket expressions; thus, a slash cannot be
283 included in a pattern bracket expression used for filename expansion. For
284 example, the pattern \fBa[b/c]d\fR will not match such pathnames as \fBabd\fR
285 or \fBa/d\fR. It will only match a pathname of literally \fBa[b/c]d\fR.
287 .RS +4
290 If a filename begins with a period (.), the period must be explicitly
291 matched by using a period as the first character of the pattern or immediately
292 following a slash character. The leading period will not be matched by:
294 \(bu the asterisk or question-mark special characters
296 \(bu a bracket expression containing a non-matching list, such as:
298 \fB[!a]\fR
300 a range expression, such as:
302 \fB[%\(mi0]\fR
304 or a character class expression, such as:
306 \fB[[:punct:]]\fR
308 It is unspecified whether an explicit period in a bracket expression matching
309 list, such as:
311 \fB[.abc]\fR
313 can match a leading period in a filename.
315 .RS +4
318 Specified patterns are matched against existing filenames and pathnames,  as
319 appropriate.  Each component that contains a pattern character requires read
320 permission in the directory containing that component. Any component, except
321 the last, that does not contain a pattern character requires search permission.
322 For example, given the pattern:
324 \fB/foo/bar/x*/bam\fR
326 search permission is needed for directories \fB/\fR and \fBfoo\fR, search and
327 read permissions are needed for directory \fBbar\fR, and search permission is
328 needed for each \fBx*\fR directory.
330 If the pattern matches any existing filenames or pathnames, the pattern will be
331 replaced with those filenames and pathnames, sorted according to the collating
332 sequence in effect in the current locale. If the pattern contains an invalid
333 bracket expression or does not match any existing filenames or pathnames, the
334 pattern string is left unchanged.
336 .SH SEE ALSO
338 \fBfind\fR(1), \fBksh\fR(1), \fBfnmatch\fR(3C), \fBregex\fR(5)