bin/166842: bsdgrep(1) inconsistently handles ^ in non-anchoring positions

Jim Pryor dubiousjim at
Wed Apr 11 19:30:16 UTC 2012

The following reply was made to PR bin/166842; it has been noted by GNATS.

From: Jim Pryor <dubiousjim at>
To: bug-followup at
Subject: Re: bin/166842: bsdgrep(1) inconsistently handles ^ in non-anchoring
Date: Wed, 11 Apr 2012 15:21:01 -0400

 I've noticed some more issues with the same version of grep. I don't
 know whether they're related, but I'll append them here for now.
 $ printf abc | grep -o '^[a-c]'
 should just print 'a', but instead gives three hits, against each letter
 of the incoming text. The same issue occurs when handling multiline
 $ printf 'abc\ndef' | grep -o --null '^[a-f]'
 incorrectly matches 6 times.
 $ printf 'abc\ndef' | grep -o --null '[a-f]$'
 correctly only matches 'c' and 'f'.
 $ printf 'abc\ndef' | grep -o --null '\`[a-f]'
 has the same issue as ^, whereas:
 $ printf 'abc\ndef' | grep -o --null '[a-f]\'\'
 matches 'c' and 'f'. To fix \` in a way that matches the behavior of \',
 it should only match the 'a' and 'd'. In fact, though, both of these
 should only match against a single character: 'a' for \` and 'f' for \'.
 That's the specified behavior of these Gnu extensions, and how they
 behave in the Gnu grep and BusyBox grep implementations I'm testing
 against. If that behavior isn't going to be provided, then wouldn't it'd
 be better for these extensions not even pretend to be present? And so,
 just match against a literal ` or '?
 dubiousjim at

More information about the freebsd-bugs mailing list