1.\" Copyright (c) 1989, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Guido van Rossum. 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)fnmatch.3 8.3 (Berkeley) 4/28/95 31.\" 32.Dd April 2, 2022 33.Dt FNMATCH 3 34.Os 35.Sh NAME 36.Nm fnmatch 37.Nd test whether a filename or pathname matches a shell-style pattern 38.Sh LIBRARY 39.Lb libc 40.Sh SYNOPSIS 41.In fnmatch.h 42.Ft int 43.Fn fnmatch "const char *pattern" "const char *string" "int flags" 44.Sh DESCRIPTION 45The 46.Fn fnmatch 47function 48matches patterns according to the rules used by the shell. 49It checks the string specified by the 50.Fa string 51argument to see if it matches the pattern specified by the 52.Fa pattern 53argument. 54.Pp 55The 56.Fa flags 57argument modifies the interpretation of 58.Fa pattern 59and 60.Fa string . 61The value of 62.Fa flags 63is the bitwise inclusive 64.Tn OR 65of any of the following 66constants, which are defined in the include file 67.In fnmatch.h . 68.Bl -tag -width FNM_PATHNAME 69.It Dv FNM_NOESCAPE 70Normally, every occurrence of a backslash 71.Pq Ql \e 72followed by a character in 73.Fa pattern 74is replaced by that character. 75This is done to negate any special meaning for the character. 76If the 77.Dv FNM_NOESCAPE 78flag is set, a backslash character is treated as an ordinary character. 79.It Dv FNM_PATHNAME 80Slash characters in 81.Fa string 82must be explicitly matched by slashes in 83.Fa pattern . 84If this flag is not set, then slashes are treated as regular characters. 85.It Dv FNM_PERIOD 86Leading periods in 87.Fa string 88must be explicitly matched by periods in 89.Fa pattern . 90If this flag is not set, then leading periods are treated as regular 91characters. 92The definition of 93.Dq leading 94is related to the specification of 95.Dv FNM_PATHNAME . 96A period is always 97.Dq leading 98if it is the first character in 99.Fa string . 100Additionally, if 101.Dv FNM_PATHNAME 102is set, 103a period is 104leading 105if it immediately follows a slash. 106.It Dv FNM_LEADING_DIR 107Ignore 108.Dq Li /* 109rest after successful 110.Fa pattern 111matching. 112.It Dv FNM_CASEFOLD 113Ignore case distinctions in both the 114.Fa pattern 115and the 116.Fa string . 117.El 118.Sh RETURN VALUES 119The 120.Fn fnmatch 121function returns zero if 122.Fa string 123matches the pattern specified by 124.Fa pattern , 125otherwise, it returns the value 126.Dv FNM_NOMATCH . 127.Sh SEE ALSO 128.Xr sh 1 , 129.Xr glob 3 , 130.Xr regex 3 131.Sh STANDARDS 132The current implementation of the 133.Fn fnmatch 134function 135.Em does not 136conform to 137.St -p1003.2 . 138Collating symbol expressions, equivalence class expressions and 139character class expressions are not supported. 140.Sh HISTORY 141A predecessor to 142.Fn fnmatch , 143.Fn gmatch , 144first appeared in the Programmer's Workbench (PWB/UNIX). 145The 146.Fn fnmatch 147function first appeared in 148.Bx 4.4 . 149.Sh BUGS 150The pattern 151.Ql * 152matches the empty string, even if 153.Dv FNM_PATHNAME 154is specified. 155