Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15386

Re: Incorrect example for `[[` command.

From hk <hkadeveloper@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Incorrect example for `[[` command.
Date 2019-09-21 08:12 +0800
Message-ID <mailman.669.1569024793.2190.bug-bash@gnu.org> (permalink)
References <CAD0rTC7W20s7-8np7Z+CmZQczTQ+LX=Y1x01gAenewrpiJS5jw@mail.gmail.com> <8e7c8ea4-2fdf-4809-0b50-ea1bfbbec165@case.edu> <CAD0rTC68qoXvCV9SLP1dJ8Gvg71W7bg9yt8jjpmpESK-jKD7Wg@mail.gmail.com>

Show all headers | View raw


Thanks for the reply. I was wrong in my report. It does match values like
aab and  aaaaaab  in its original form.

What is wrong is the description `zero or one instances of 'a''. But if we
correct the right hand side word to be  `[[:space:]]*(a)?b' that it does
match what the description says.(the parenthese around `a' could be
omitted).

I was also wrong saying it was a pattern instead of a regular expression.
It is syntatically correct as a regular expression. A word can be
syntactically correct as a pattern and a regular expression at the same
time though the semantic might be different in most cases.

On Fri, Sep 20, 2019 at 11:48 PM Chet Ramey <chet.ramey@case.edu> wrote:

> On 9/20/19 1:40 AM, hk wrote:
>
> > Bash Version: 5.0
> > Patch Level: 0
> > Release Status: release
> >
> > Description:
> >         On section 3.2.4.2 of Bash Reference Manual, the example on*
> > [[...]]* (page 13 in the PDF) is incorrect. Specifically, the example
> say *[[
> > $line =~ [[:space:]]*?(a)b ]]*  will match values like *'aab'* and*
> > 'aaaaaab*'. But it won't. The operator is* =~*, but the operand on the
> > right side is a pattern while it should be a regular expression.
>
> Thanks for the report, this is a good catch. It's been this way since 2011.
>
> It's supposed to be a regular expression, and there's a typo. You're right
> that it doesn't match the same things as if it were interpreted as a shell
> pattern.
>
> The pattern would match the description if it were `[[:space:]]*(a)?b'.
>
> The pattern, once corrected, does match the strings in the example below,
> since, as the description says, it matches "a sequence of characters in the
> value."
>
> The regexp is unanchored, though you can anchor it yourself. That's
> arguably less useful than the anchored case (like, say, grep), but that's
> what you get from regcomp/regexec, and you have $BASH_REMATCH to see what
> you matched.
>
> Chet
>
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/
>

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Incorrect example for `[[` command. hk <hkadeveloper@gmail.com> - 2019-09-21 08:12 +0800

csiph-web