STRMATCH(3)
π
STRMATCH(3) β the strmatch page, bestie edition π
okay so real talk, this is the strmatch page from the Library Functions Manual, and it's all about matching shell file patterns. it's short, it's cute, it's giving "tiny function, big power" energy. let's get into it β¨
β¨ NAME β¨
strmatch β match shell file patterns π
πΈ SYNOPSIS πΈ
int strmatch(char* s, char* p)
char* submatch(char* s, char* p, int m)
like, that's it. two functions. no cap. π
π¦ DESCRIPTION π¦
okay so strmatch compares the string s with the shell pattern p and returns 1 for match and 0 otherwise. simple! icon behavior honestly π
submatch is the main character here β it does a leading substring match of the shell pattern p with the string s. and then m is the vibe check:
- if
mis0β the match is minimal - otherwise β a maximal match is done β¨
what does it give you back? a pointer to the first character after the matched substring. and if there's no match at all? 0. tragic, but that's the rule π
π the pattern cheat sheet π
except for & and !, each shell pattern has an equivalent egrep(1) construct. so here's the full rundown, every single row, no skipping π:
*β egrep:.*β 0 or more chars?β egrep:.β any single char[.]β egrep:[.]β char class[!.]β egrep:[^.]β negated char class*(.)β egrep:(.)*β 0 or more of+(.)β egrep:(.)+β 1 or more of?(.)β egrep:(.)?β 0 or 1 of(.)β egrep:(.)β 1 of@(.)β egrep:(.)β 1 ofa|bβ egrep:a|bβ a or ba&bβ no egrep equivalent β a and b!(.)β no egrep equivalent β none of
bestie notice how & and ! are the two that don't play nice with egrep? yeah. that's the whole exception. π«Ά
π§ escaping, aka the backslash moment π§
\ is used to escape *, ?, (, |, &, ), [, and \ β but only outside of [...]. so inside a char class, backslash isn't doing that job. iykyk π
lowkey important: that list of escapable characters is exact β*,?,(,|,&,),[, and\. don't be out here escaping random stuff and expecting magic, okay? π
π SEE ALSO π
grep(1)β the whole egrep-adjacent crossover episode you didn't know you needed π
π BUGS π
the receipts, and they're not cute:
- An unbalanced
)terminates the top level pattern. fr fr, one stray paren and the whole top level is done for π - Nested
&and!constructs are non-intuitive and are computationally intensive. so like... they work, but they're weird to reason about AND they eat CPU. highkey a vibe killer π
π sign-off π
and that's the whole page, bestie β the footer is literally just STRMATCH(3) and nothing else, no date, no version, so consider this your little goodbye kiss from the Library Functions Manual. go forth and pattern-match slay π
β¨π¦
π¦ where this page comes from
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- opensuse-leap 16.0: ksh-devel 93vu-bp160.1.33 Β· CPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms