Subject: 'grep --ignore-case --color' does not always color the matches

From: Benno Schulenberg <[email-masked]>
Date: Wed, 19 Feb 2020 11:18:18 +0100

echo a | grep -i --color '\a'

  echo a | grep -i --color '\A'

Of the above two commands, only the second colorizes the printed "a".

(An old GNU grep on NetBSD (grep 2.5.1a nb1) does the opposite of
a modern grep: it will show color for \a, but none for \A.)

Bug was found in GNU grep 3.1 while checking whether it understands
\d as a shorthand for [0-9].  Still present in 3.4. The locale does
not appear to matter.

In a report against glibc [1] that seems to be related, a comment
says that "Unknown backslash escapes invoke undefined behaviour."
But where in the documentation does it say so?

When searching for a regular expression in GNU nano (^W M-R), nano says
it cannot find any \a.  But for \A, it will find all "a"s and "A"s.
Nano's default search is case insensitive.  See [2] for the original
report by Ben Addis.  I suppose this is the same or a related bug in
the regex module of gnulib, which nano uses.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=22425

[2] https://savannah.gnu.org/bugs/?57852

Benno