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


Groups > gnu.bash.bug > #14309 > unrolled thread

Re: Word boundary anchors \< and \> not parsed correctly on the right side of =~

Started byPaulo Marcel Coelho Aragão <marcelpaulo@gmail.com>
First post2018-07-10 10:02 -0300
Last post2018-07-10 10:02 -0300
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Word boundary anchors \< and \> not parsed correctly on the right side of =~ Paulo Marcel Coelho Aragão <marcelpaulo@gmail.com> - 2018-07-10 10:02 -0300

#14309 — Re: Word boundary anchors \< and \> not parsed correctly on the right side of =~

FromPaulo Marcel Coelho Aragão <marcelpaulo@gmail.com>
Date2018-07-10 10:02 -0300
SubjectRe: Word boundary anchors \< and \> not parsed correctly on the right side of =~
Message-ID<mailman.3368.1531227765.1292.bug-bash@gnu.org>
On Tue, Jul 10, 2018 at 08:27:18AM -0400, Greg Wooledge wrote:
> Bash uses ERE (Extended Regular Expressions) here.  There is no \< or \>
> in an ERE.
> 
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04

Thanks for the reference. The document lists only ^ and $ as anchors. However, this indicates to me that bash recognizes \< \> as word anchors:

    paulo:~$ re='\<foo\>'
    paulo:~$ [[ 'foo bar' =~ $re ]] && echo yes || echo no
    yes
    paulo:~$ [[ 'foobar' =~ $re ]] && echo yes || echo no
    no

It baffles me that literal \< \> are not evaluated correctly

    paulo:~$ [[ 'foo bar' =~ \<foo\> ]] && echo yes || echo no
    no

This indicates that bash also recognizes \b as word anchor:

    paulo:~$ re='\bfoo\b'
    paulo:~$ [[ 'foo bar' =~ $re ]] && echo yes || echo no
    yes
    paulo:~$ [[ 'foobar' =~ $re ]] && echo yes || echo no
    no

but it also baffles me literal \b is not evaluated correctly:

    paulo:~$ [[ 'foo bar' =~ \bfoo\b ]] && echo yes || echo no
    no

Empirically all this demonstrates:

1. bash recognizes \< \> \b as word anchors
2. bash doesn't evaluate them correctly when used as literals
3. bash evaluates them correctly when used with parameter expansion

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web