Grep : ‘+’ special character

grep

I did some simple tests with grep '+' and '*' special character

$ echo 'where wh+'> /tmp/toto
$ grep 'wh[e]\*' /tmp/toto
$ grep 'wh[e]*' /tmp/toto
where wh+
$ grep 'wh[e]+' /tmp/toto
$ grep 'wh+' /tmp/toto
$ grep 'wh[e]\+' /tmp/toto
where
$ grep -E 'wh[e]*' /tmp/toto
where wh+
$ grep -E 'wh[e]+' /tmp/toto
where wh+

From theses tests, non extended grep '+' (and '?') is not interpreted as a special character, in order to use it as a special character it must be escaped. As I read, grep uses Basic Regular Expressions (without -E option), in this case, special characters are defined here :
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_03
and '?' '+' are not special characters for BRE.

But why does escaping non special character '+' in a BRE makes it special character?

Best Answer

This is a GNU extension. From the grep(1) manpage:

In GNU grep, there is no difference in available functionality between basic and extended syntaxes. In other implementations, basic regular expressions are less powerful. The following description applies to extended regular expressions; differences for basic regular expressions are summarized afterwards.

and further down

Basic vs Extended Regular Expressions

In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \).

Related Question