SHELLEXP(3) - Linux man page online | Library functions

Match string against a cruft filter pattern.

October 17, 2007
SHELLEXP(3) Library Functions Manual SHELLEXP(3)


shellexp - match string against a cruft filter pattern


extern int shellexp(const char *string, const char *pattern);


The shellexp() function is similar to fnmatch(3), but works with cruft patterns instead of standard glob(7) patterns. The function returns a true value if string matches the cruft pattern pattern, and a false value (0) otherwise. Returns -1 in case of pattern syntax error. Cruft patterns are similar to glob(7) patterns, but are not fully compatible. The follow‐ ing special characters are supported: ? (a question mark) matches exactly one character of string other than a slash. * matches zero or more characters of string other than a slash. /** or /**/ matches zero or more path components in string. Please note that you can only use ** when directly following a slash, and furthermore, only when either directly pre‐ ceding a slash or at the very end of pattern. A ** followed by anything other than a slash makes pattern invalid. A ** following anything else than a slash reduces it to having the same effect as *. [character-class] Matches any character between the brackets exactly once. Named character classes are NOT supported. If the first character of the class is ! or ^, then the meaning is inverted (matches any character NOT listed between the brackets). If you want to specify a literal closing bracket in the class, then specify it as the first (or second, if you want to negate) character after the opening bracket. Also, simple ASCII-order ranges are supported using a dash character (see examples section). Any other character matches itself.


/a/b*/*c matches /a/b/xyz.c, as well as /a/bcd/.c, but not /a/b/c/d.c. /a/**/*.c matches all of the following: /a/a.c, /a/b/a.c, /a/b/c/a.c and /a/b/c/d/a.c. /a/[0-9][^0-9]* matches /a/1abc, but not /a/12bc.


Uses constant-length 1000 byte buffers to hold filenames. Also uses recursive function calls, which are not very efficient. Does not validate the pattern before matching, so any pattern errors (unbalanced brackets or misplaced **) are only reported when and if the matching algorithm reaches them.


fnmatch(3), glob(3), cruft(8) and dash-search(1).


This manual page was written by Marcin Owsiany <>, for the Debian GNU/Linux system (but may be used by others).
October 17, 2007 SHELLEXP(3)
This manual Reference Other manuals
shellexp(3) referred by dash-search(1)
refer to cruft(8) | dash-search(1) | fnmatch(3) | glob(3) | glob(7)
Download raw manual
Main page Library Functions Manual (+5028) № 3 (+68044)
Go top