| 1 |
'\" t |
| 2 |
.\" Copyright (c) 1993 by Thomas Koenig ([email protected]) |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.\" Modified Sat Jul 24 19:35:54 1993 by Rik Faith ([email protected]) |
| 7 |
.\" Modified Mon Oct 16 00:16:29 2000 following Joseph S. Myers |
| 8 |
.\" |
| 9 |
.TH fnmatch 3 2024-05-02 "Linux man-pages 6.9.1" |
| 10 |
.SH NAME |
| 11 |
fnmatch \- match filename or pathname |
| 12 |
.SH LIBRARY |
| 13 |
Standard C library |
| 14 |
.RI ( libc ", " \-lc ) |
| 15 |
.SH SYNOPSIS |
| 16 |
.nf |
| 17 |
.B #include <fnmatch.h> |
| 18 |
.P |
| 19 |
.BI "int fnmatch(const char *" "pattern" ", const char *" string ", int " flags ); |
| 20 |
.fi |
| 21 |
.SH DESCRIPTION |
| 22 |
The |
| 23 |
.BR fnmatch () |
| 24 |
function checks whether the |
| 25 |
.I string |
| 26 |
argument matches the |
| 27 |
.I pattern |
| 28 |
argument, which is a shell wildcard pattern (see |
| 29 |
.BR glob (7)). |
| 30 |
.P |
| 31 |
The |
| 32 |
.I flags |
| 33 |
argument modifies the behavior; it is the bitwise OR of zero or more |
| 34 |
of the following flags: |
| 35 |
.TP |
| 36 |
.B FNM_NOESCAPE |
| 37 |
If this flag is set, treat backslash as an ordinary character, |
| 38 |
instead of an escape character. |
| 39 |
.TP |
| 40 |
.B FNM_PATHNAME |
| 41 |
If this flag is set, match a slash in |
| 42 |
.I string |
| 43 |
only with a slash in |
| 44 |
.I pattern |
| 45 |
and not by an asterisk (*) or a question mark (?) metacharacter, |
| 46 |
nor by a bracket expression ([]) containing a slash. |
| 47 |
.TP |
| 48 |
.B FNM_PERIOD |
| 49 |
If this flag is set, a leading period in |
| 50 |
.I string |
| 51 |
has to be matched exactly by a period in |
| 52 |
.IR pattern . |
| 53 |
A period is considered to be leading if it is the first character in |
| 54 |
.IR string , |
| 55 |
or if both |
| 56 |
.B FNM_PATHNAME |
| 57 |
is set and the period immediately follows a slash. |
| 58 |
.TP |
| 59 |
.B FNM_FILE_NAME |
| 60 |
This is a GNU synonym for |
| 61 |
.BR FNM_PATHNAME . |
| 62 |
.TP |
| 63 |
.B FNM_LEADING_DIR |
| 64 |
If this flag (a GNU extension) is set, the pattern is considered to be |
| 65 |
matched if it matches an initial segment of |
| 66 |
.I string |
| 67 |
which is followed by a slash. |
| 68 |
This flag is mainly for the internal |
| 69 |
use of glibc and is implemented only in certain cases. |
| 70 |
.TP |
| 71 |
.B FNM_CASEFOLD |
| 72 |
If this flag (a GNU extension) is set, the pattern is matched |
| 73 |
case-insensitively. |
| 74 |
.TP |
| 75 |
.B FNM_EXTMATCH |
| 76 |
If this flag (a GNU extension) is set, extended patterns are |
| 77 |
supported, as introduced by \&'ksh' and now supported by other shells. |
| 78 |
The extended format is as follows, with \fIpattern\-list\fR |
| 79 |
being a \&'|' separated list of patterns. |
| 80 |
.TP |
| 81 |
\&'?(\fIpattern\-list\fR)' |
| 82 |
The pattern matches if zero or one occurrences of any of the |
| 83 |
patterns in the \fIpattern\-list\fR match the input \fIstring\fR. |
| 84 |
.TP |
| 85 |
\&'*(\fIpattern\-list\fR)' |
| 86 |
The pattern matches if zero or more occurrences of any of the |
| 87 |
patterns in the \fIpattern\-list\fR match the input \fIstring\fR. |
| 88 |
.TP |
| 89 |
\&'+(\fIpattern\-list\fR)' |
| 90 |
The pattern matches if one or more occurrences of any of the |
| 91 |
patterns in the \fIpattern\-list\fR match the input \fIstring\fR. |
| 92 |
.TP |
| 93 |
\&'@(\fIpattern\-list\fR)' |
| 94 |
The pattern matches if exactly one occurrence of any of the |
| 95 |
patterns in the \fIpattern\-list\fR match the input \fIstring\fR. |
| 96 |
.TP |
| 97 |
\&'!(\fIpattern\-list\fR)' |
| 98 |
The pattern matches if the input \fIstring\fR cannot be matched with |
| 99 |
any of the patterns in the \fIpattern\-list\fR. |
| 100 |
.SH RETURN VALUE |
| 101 |
Zero if |
| 102 |
.I string |
| 103 |
matches |
| 104 |
.IR pattern , |
| 105 |
.B FNM_NOMATCH |
| 106 |
if there is no match or another nonzero value if there is an error. |
| 107 |
.SH ATTRIBUTES |
| 108 |
For an explanation of the terms used in this section, see |
| 109 |
.BR attributes (7). |
| 110 |
.TS |
| 111 |
allbox; |
| 112 |
lbx lb lb |
| 113 |
l l l. |
| 114 |
Interface Attribute Value |
| 115 |
T{ |
| 116 |
.na |
| 117 |
.nh |
| 118 |
.BR fnmatch () |
| 119 |
T} Thread safety MT-Safe env locale |
| 120 |
.TE |
| 121 |
.SH STANDARDS |
| 122 |
.TP |
| 123 |
.BR fnmatch () |
| 124 |
POSIX.1-2008. |
| 125 |
.TP |
| 126 |
.B FNM_FILE_NAME |
| 127 |
.TQ |
| 128 |
.B FNM_LEADING_DIR |
| 129 |
.TQ |
| 130 |
.B FNM_CASEFOLD |
| 131 |
GNU. |
| 132 |
.SH HISTORY |
| 133 |
.TP |
| 134 |
.BR fnmatch () |
| 135 |
POSIX.1-2001, POSIX.2. |
| 136 |
.SH SEE ALSO |
| 137 |
.BR sh (1), |
| 138 |
.BR glob (3), |
| 139 |
.BR scandir (3), |
| 140 |
.BR wordexp (3), |
| 141 |
.BR glob (7) |