String Pattern Functions

To simplify program development of shells and other related functions that require this pattern matching capability, the function fnmatch(3) was developed. The function synopsis for it is as follows:

#include <fnmatch.h>

int fnmatch(const char *pattern, const char *string, int flags);

The argument pattern is the input pattern string, which is compared with the input argument string. The argument pattern contains the meta-characters, if any. The argument string is the string that you want to test for a match. The argument flags enables and disables certain features of the fnmatch(3) function.

The return value from fnmatch(3) is zero if a match is made. Otherwise, the value FNM_NOMATCH is returned instead.

Note

When the ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.