Re: Bookworm: dash shell globs don't recognise [^...] to negate a character class
On Fri, Apr 14, 2023 at 09:08:08AM +0700, Max Nikulin wrote:
> On 13/04/2023 08:07, Greg Wooledge wrote:
> > On Thu, Apr 13, 2023 at 12:12:23AM +0000, David wrote:
> > > $ echo [^0-9]*
> > > 11 22 <------ new behaviour by dash
> [...]
> > The correct negation syntax in POSIX sh globs is [!chars].
>
> The shellcheck utility gives this suggestion as well. Their wiki have
> concise description of the issue, but links describing it in more details
> with precise references have not been added yet.
>
> https://www.shellcheck.net/wiki/SC3026
> > Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc
Well, it's not clear how to actually add such a link. I guess you're
supposed to do it through github or something?
Anyway, here's the POSIX documentation section:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_13
And the relevant piece of text:
[ If an open bracket introduces a bracket expression as in XBD RE
Bracket Expression, except that the <exclamation-mark> character
( '!' ) shall replace the <circumflex> character ( '^' ) in its
role in a non-matching list in the regular expression notation, it
shall introduce a pattern bracket expression. A bracket expression
starting with an unquoted <circumflex> character produces unspecified
results. Otherwise, '[' shall match the character itself.
Reply to: