bug-bash
[Top][All Lists]
Advanced

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

Re: Incorrect example for `[[` command.


From: Chet Ramey
Subject: Re: Incorrect example for `[[` command.
Date: Fri, 20 Sep 2019 11:48:08 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

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/



reply via email to

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