The following issue has been SUBMITTED. ====================================================================== https://www.austingroupbugs.net/view.php?id=1558 ====================================================================== Reported By: stephane Assigned To: ====================================================================== Project: 1003.1(2016/18)/Issue7+TC2 Issue ID: 1558 Category: Shell and Utilities Type: Enhancement Request Severity: Objection Priority: normal Status: New Name: Stephane Chazelas Organization: User Reference: Section: 2.13.1 Patterns Matching a Single Character Page Number: 2352 Line Number: 76144 Interp Status: --- Final Accepted Text: ====================================================================== Date Submitted: 2022-01-24 08:51 UTC Last Modified: 2022-01-24 08:51 UTC ====================================================================== Summary: require [^...] in addition to [!...] for bracket expression negation Description: (page/line numbers above are from Draft 2.1)
There's a very unfortunate difference between sh/fnmatch globs and regexps in that [^...] is used in regexps (and most other places/languages) and [!...] in sh/fnmatch wildcard patterns (and [~...] in rc/es though that's not relevant here). The only reason is that the Bourne shell had decided to keep ^ as a pipe operator for backward compatibility with the Thompson shell, and since it's not an error there to have [ / ] unmatched, ^ could not be used as negation operator inside bracket expressions. But POSIX sh it not and is not compatible with the Bourne shell and POSIX does not allow ^ be treated specially, and leaves [^...] unspecified, more or less explicitly allowing ^ to be used as negation there and it's been the case for decades. Most sh/fnmatch implementations have now moved on and allow [^...] for negation. Among common sh implementations, the only exceptions that I know are ksh88 (and pdksh and derivatives) and bosh (that one still treats ^ as a pipe operator except with -o posix). All of bash, zsh, yash, dash, BSDs (except those like OpenBSD, MirBSD that use pdksh) allow [^...]. Most fnmatch() implementations do (including on OpenBSD making it a discrepancy between sh and fnmatch()/find...). Desired Action: Require [^...] to negate the bracket expression in addition to [!...] in issue8, or at least make it a "future direction" that it *will* be required in a future version, so as to at last remove that unnecessary discrepancy between regexp and shell pattern syntax. [!...] would have to be retained for backward compatibility (making it a remaining difference with regexps). [\^!] and [\!^] can both be used to match either ^ or ! (ksh93 is not compliant to that atm but it looks like it's the only one). ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 2022-01-24 08:51 stephane New Issue 2022-01-24 08:51 stephane Name => Stephane Chazelas 2022-01-24 08:51 stephane Section => 2.13.1 Patterns Matching a Single Character 2022-01-24 08:51 stephane Page Number => 2352 2022-01-24 08:51 stephane Line Number => 76144 ======================================================================