bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Incorrect example for `[[` command.


From: Greg Wooledge
Subject: Re: Incorrect example for `[[` command.
Date: Fri, 20 Sep 2019 08:48:27 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Fri, Sep 20, 2019 at 01:40:00PM +0800, hk wrote:
> 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.

Nice catch.

Actually it's a mixture of a regular expression (the postfix * closure
operator) and an extended glob (the ?() enclosing syntax).  So it wouldn't
work with either = or =~ .

Even more subtly wrong, the sentence before the first instance of this
regex-glob-thing says:

  any number, including zero, of space characters, zero or one instances
  of ‘a’, then a ‘b’

but after the regex-glob-thing, it says:

  That means values like ‘aab’ and ‘ aaaaaab’ will match

So there's a shift in intent between a? and a+ in what's supposed to be
a regular expression.  Although of course the sentence is *literally*
true because the regex would be unanchored, and therefore it's sufficient
to match only the 'ab', and the rest of the input doesn't matter.
But that's just confusing, and doesn't belong in this kind of document.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]