1fnmatch(3) Library Functions Manual fnmatch(3)
2
3
4
6 fnmatch - match filename or pathname
7
9 Standard C library (libc, -lc)
10
12 #include <fnmatch.h>
13
14 int fnmatch(const char *pattern, const char *string, int flags);
15
17 The fnmatch() function checks whether the string argument matches the
18 pattern argument, which is a shell wildcard pattern (see glob(7)).
19
20 The flags argument modifies the behavior; it is the bitwise OR of zero
21 or more of the following flags:
22
23 FNM_NOESCAPE
24 If this flag is set, treat backslash as an ordinary character,
25 instead of an escape character.
26
27 FNM_PATHNAME
28 If this flag is set, match a slash in string only with a slash
29 in pattern and not by an asterisk (*) or a question mark (?)
30 metacharacter, nor by a bracket expression ([]) containing a
31 slash.
32
33 FNM_PERIOD
34 If this flag is set, a leading period in string has to be
35 matched exactly by a period in pattern. A period is considered
36 to be leading if it is the first character in string, or if both
37 FNM_PATHNAME is set and the period immediately follows a slash.
38
39 FNM_FILE_NAME
40 This is a GNU synonym for FNM_PATHNAME.
41
42 FNM_LEADING_DIR
43 If this flag (a GNU extension) is set, the pattern is considered
44 to be matched if it matches an initial segment of string which
45 is followed by a slash. This flag is mainly for the internal
46 use of glibc and is implemented only in certain cases.
47
48 FNM_CASEFOLD
49 If this flag (a GNU extension) is set, the pattern is matched
50 case-insensitively.
51
52 FNM_EXTMATCH
53 If this flag (a GNU extension) is set, extended patterns are
54 supported, as introduced by 'ksh' and now supported by other
55 shells. The extended format is as follows, with pattern-list
56 being a '|' separated list of patterns.
57
58 '?(pattern-list)'
59 The pattern matches if zero or one occurrences of any of the
60 patterns in the pattern-list match the input string.
61
62 '*(pattern-list)'
63 The pattern matches if zero or more occurrences of any of the
64 patterns in the pattern-list match the input string.
65
66 '+(pattern-list)'
67 The pattern matches if one or more occurrences of any of the
68 patterns in the pattern-list match the input string.
69
70 '@(pattern-list)'
71 The pattern matches if exactly one occurrence of any of the pat‐
72 terns in the pattern-list match the input string.
73
74 '!(pattern-list)'
75 The pattern matches if the input string cannot be matched with
76 any of the patterns in the pattern-list.
77
79 Zero if string matches pattern, FNM_NOMATCH if there is no match or an‐
80 other nonzero value if there is an error.
81
83 For an explanation of the terms used in this section, see at‐
84 tributes(7).
85
86 ┌─────────────────────────────────┬───────────────┬────────────────────┐
87 │Interface │ Attribute │ Value │
88 ├─────────────────────────────────┼───────────────┼────────────────────┤
89 │fnmatch() │ Thread safety │ MT-Safe env locale │
90 └─────────────────────────────────┴───────────────┴────────────────────┘
91
93 fnmatch()
94 POSIX.1-2008.
95
96 FNM_FILE_NAME
97 FNM_LEADING_DIR
98 FNM_CASEFOLD
99 GNU.
100
102 fnmatch()
103 POSIX.1-2001, POSIX.2.
104
106 sh(1), glob(3), scandir(3), wordexp(3), glob(7)
107
108
109
110Linux man-pages 6.05 2023-07-20 fnmatch(3)