On 2025-10-01 12:16, Seth David Schoen wrote:
$ echo 'hello{' | egrep '{'
hello{
$ echo 'hello[' | egrep '['
grep: Invalid regular expression
You're right that it's inconsistent. However, it's what AT&T/Sun egrep
does. I just now confirmed this with Solaris 10 /usr/bin/egrep:
$ echo 'hello{' | egrep '{'
hello{
$ echo 'hello[' | egrep '['
egrep: syntax error
7th Edition Unix egrep did not treat '{' as a metacharacter, and I
suspect that when AT&T (or Sun?) added support for '{...}' they did not
want to break existing scripts that used '{' as an ordinary character.
When GNU grep was written, its developers didn't want to break existing
scripts that assumed AT&T/Sun behavior, so they copied this
inconsistency. And changing GNU grep's behavior now might break things.
At least GNU grep's behavior is documented for these corner cases. You
probably won't be so lucky with non-GNU grep.