SHELLEXP(3)
π NAME π
okay bestie, meet shellexp β she matches a string against a cruft filter pattern. that's the whole vibe. β¨
π SYNOPSIS π
extern int shellexp(const char *string, const char *pattern);
β¨ DESCRIPTION β¨
so shellexp() is basically fnmatch(3)'s cooler cousin, except instead of standard glob(7) patterns she works with cruft patterns. iconic behavior honestly.
She returns a true value when string matches the cruft pattern pattern, and a false value (0) otherwise. And if the pattern has a syntax error? She returns -1. not her fault, the pattern was messy. π
Cruft patterns are similar to glob(7) patterns but not fully compatible β think "inspired by, not copying." π¦ The special characters she supports are:
?(a question mark) β matches exactly one character ofstring, and not a slash. just one. she's picky.*β matches zero or more characters ofstring, again not a slash. zero is allowed, she's generous like that. π/**or/**/β matches zero or more path components instring. okay but hear me out, the rules here are specific:- you can only use
**when it's directly following a slash, and - furthermore only when it's either directly preceding a slash or at the very end of
pattern. - a
**followed by anything other than a slash makespatterninvalid. periodt. - a
**following anything else than a slash gets reduced to having the same effect as*. she's humbled. π
- you can only use
[character-class]β matches any character between the brackets exactly once. Named character classes are NOT supported, sorry to the[:alpha:]girlies. If the first character of the class is!or^, the meaning is inverted (so it matches any character NOT listed between the brackets). Wanna put a literal closing bracket in the class? specify it as the first character after the opening bracket β or the second, if you're negating. also, simple ASCII-order ranges are supported using a dash character (peep the examples section π).- Any other character matches itself. simple. no drama. πΈ
π EXAMPLES π
/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.cand/a/b/c/d/a.c. she ate that. π/a/[0-9][^0-9]*β matches/a/1abc, but not/a/12bc.
π BUGS π
ngl there's some stuff you should know:
- She uses constant-length 1000 byte buffers to hold filenames. yeah. 1000. exactly.
- She also uses recursive function calls, which are not very efficient. it's giving "works but don't stress her."
- She 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. so like, she'll find out mid-match. live your truth I guess. π
π«Ά SEE ALSO π«Ά
fnmatch(3), glob(3), cruft(8) and dash-search(1).
π AUTHOR π
This manual page was written by Marcin Owsiany <porridge@debian.org>, for the Debian GNU/Linux system (but may be used by others). shoutout to them fr fr. π
and that's a wrap bestie!! this page is from the Library Functions Manual, dated October 17, 2007 β SHELLEXP(3) forever in our hearts. bye bye, go match some patterns responsibly π
β¨
π¦ where this page comes from
- ubuntu jammy: cruft 0.9.40 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms