# man > fnmatch(3am)

---
type: CommandReference
command: fnmatch
mode: man
section: 3am
source: man-pages
---

## Quick Reference

- `fnmatch("*.a", "foo.c", flags)` — returns 0 if string matches the filename wildcard pattern, `FNM_NOMATCH` otherwise.
- `@load "fnmatch"` — load the extension before use.

## Name

fnmatch — compare a string against a filename wildcard

## Synopsis

awk
@load "fnmatch"
result = fnmatch(pattern, string, flags)
## Options

Flags are passed as the third argument, bitwise OR of values from the `FNM` array:

- `FNM["CASEFOLD"]` — match case-insensitively (corresponds to `FNM_CASEFOLD`)
- `FNM["FILE_NAME"]` — corresponds to `FNM_FILE_NAME`
- `FNM["LEADING_DIR"]` — corresponds to `FNM_LEADING_DIR`
- `FNM["NOESCAPE"]` — treat backslash as ordinary character (corresponds to `FNM_NOESCAPE`)
- `FNM["PATHNAME"]` — slash in string only matches literal slash in pattern (corresponds to `FNM_PATHNAME`)
- `FNM["PERIOD"]` — leading period in string must be matched explicitly (corresponds to `FNM_PERIOD`)

## Examples

awk
@load "fnmatch"
...
flags = or(FNM["PERIOD"], FNM["NOESCAPE"])
if (fnmatch("*.a", "foo.c", flags) == FNM_NOMATCH)
    print "no match"
## Notes

- The predefined variable `FNM_NOMATCH` is the return value when the string does not match the pattern. Modifying it may cause strange results.
- Return value 0 on success, non-zero on error.

## See Also

- [fnmatch(3)](http://localhost/phpMan.php/man/fnmatch/3/markdown)
- [filefuncs(3am)](http://localhost/phpMan.php/man/filefuncs/3am/markdown)
- [fork(3am)](http://localhost/phpMan.php/man/fork/3am/markdown)
- [inplace(3am)](http://localhost/phpMan.php/man/inplace/3am/markdown)
- [ordchr(3am)](http://localhost/phpMan.php/man/ordchr/3am/markdown)
- [readdir(3am)](http://localhost/phpMan.php/man/dir/3am/markdown)
- [readfile(3am)](http://localhost/phpMan.php/man/readfile/3am/markdown)
- [revoutput(3am)](http://localhost/phpMan.php/man/revoutput/3am/markdown)
- [rwarray(3am)](http://localhost/phpMan.php/man/rwarray/3am/markdown)
- [time(3am)](http://localhost/phpMan.php/man/time/3am/markdown)
- GAWK: Effective AWK Programming