All of the documentation I can find about the shExpMatch
function is awful. For example:
- findproxyforurl.com - "Will attempt to match hostname or URL to a specified shell expression"
- Microsoft - "The shExpMatch(str, shexp) function returns true if str matches the shexp using shell expression patterns."
- Mozilla "Currently, the patterns are shell expressions, not regular expressions."
I've worked with a lot of shells, and I've never seen the phrase "shell expression" used to describe a pattern-matching language before. I have no idea what it's supposed to mean. From the available examples it looks similar to a filename globbing pattern. I wonder why they don't say "glob", or "wildcard", or "filename expansion" (any of those 3 would be more standard, recognizable terms) if that's what they mean. Instead the undefined phrase "shell expression" is universally used by every vendor - but only to describe this function. If I didn't know better I'd think they were all just copying each other's documentation without reading it.
If we accept that "shell expression" means glob then the trouble is just beginning. Which shell? Do the different implementations even agree? I can guess that this function was originated by some unix programmer, whose default idea of globs was Bourne-shell-ish. But there are a lot of variants in that -ish suffix! Basic features are *
and ?
and []
. Does the []
support character classes like [[:alnum:]]
or just individual characters and ranges? Does it support negation like [!a-z]
or maybe [^a-z]
? Can all of the special characters be matched literally by preceding them with a backslash (including backslash itself)? Are there any other shell-like quoting operators? Does the *
operator really act like a glob, matching a single level of a directory hierarchy, so *
and */*
are mutually exclusive, or does it match slashes too? Does it fail to match a leading dot? Are any of the extensions from ksh
, bash
, and zsh
present? Maybe even csh
-like brace expansion (which is not a glob operation but is often mistaken for one)?
On the other hand, maybe it was designed by a Microsoft-oriented person to support Windows users, so I should think more like COMMAND.COM wildcards. Would Microsoft use a foreign pattern matching language, and not explicitly document it as such?
Is there an authoritative source that I've overlooked which actually specifies the matching rules? Failing that, has anyone studied the current implementations in enough detail to determine what the rules actually are?