Bug 191086 - grep(1) and bsdgrep(1) do not recognize [[:<:]] and [[:>:]]
Summary: grep(1) and bsdgrep(1) do not recognize [[:<:]] and [[:>:]]
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.2-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL: https://reviews.freebsd.org/D10114
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-16 13:33 UTC by Nathan Weeks
Modified: 2020-12-08 14:06 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Weeks 2014-06-16 13:33:20 UTC
grep and bsdgrep do not recognize the '[[:<:]]' or '[[:>:]]' bracket
expressions described in re_format(7), though sed does:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ printf 'foobar\nfoo bar\nbaz' | grep 'foo[[:>:]]'
grep: Invalid character class name
$ printf 'foobar\nfoo bar\nbaz' | grep '[[:<:]]bar'
grep: Invalid character class name
$ printf 'foobar\nfoo bar\nbaz' | bsdgrep 'foo[[:>:]]'
bsdgrep: Invalid character class name
$ printf 'foobar\nfoo bar\nbaz' | bsdgrep '[[:<:]]bar'
bsdgrep: Invalid character class name
$ printf 'foobar\nfoo bar\nbaz' | sed -n '/foo[[:>:]]/p'
foo bar
$ printf 'foobar\nfoo bar\nbaz' | sed -n '/[[:<:]]bar/p'
foo bar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-- 
Nathan Weeks
IT Specialist
USDA-ARS Corn Insects and Crop Genetics Research Unit
Crop Genome Informatics Laboratory
Iowa State University
http://weeks.public.iastate.edu/
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2017-01-21 19:24:34 UTC
(In reply to weeks from comment #0)

Hi,

This is another issue that comes with GNU_GREP_COMPAT. I don't suspect there's much hope that this will change, though -- tested on a relatively new Debian system, GNU grep and sed *both* fail recognize these as character classes. 

This is otherwise resolved by compiling bsdgrep with WITHOUT_GNU_GREP_COMPAT="YES" set in /etc/src.conf.
Comment 2 Nathan Weeks 2017-01-23 14:50:10 UTC
OK. It's interesting to note that OS X 10.11.6, which also uses bsdgrep, does support the '[[:<:]]' and '[[:>:]]' bracket expressions:
 
$ uname -srv
Darwin 15.6.0 Darwin Kernel Version 15.6.0: Mon Jan  9 23:07:29 PST 2017; root:xnu-3248.60.11.2.1~1/RELEASE_X86_64
$ type grep
grep is a tracked alias for /usr/bin/grep
$ grep --version
grep (BSD grep) 2.5.1-FreeBSD
$ printf 'foobar\nfoo bar\nbaz' | grep 'foo[[:>:]]'
foo bar
$ printf 'foobar\nfoo bar\nbaz' | grep '[[:<:]]bar'
foo bar
Comment 3 Ed Maste freebsd_committer freebsd_triage 2017-01-23 14:55:48 UTC
> OK. It's interesting to note that OS X 10.11.6, which also uses bsdgrep, does
> support the '[[:<:]]' and '[[:>:]]' bracket expressions:

Apple's bsdgrep has a few bug fixes. Unfortunately I've not yet been able to find the source for these changes.
Comment 4 Kyle Evans freebsd_committer freebsd_triage 2017-01-23 14:56:16 UTC
(In reply to weeks from comment #2)

Yeah, the odds are quite good that they don't have an option that uses GNU regex stuff instead of their own, which is the problem that we have. Our regex stuff supports it, but GNU's does not and linking against GNU is the default here.

I've pondered elsewhere if it would be a good idea to make this not the default on a BSD system, and again it would seem to be a good idea.
Comment 5 Enji Cooper freebsd_committer freebsd_triage 2017-01-23 18:23:08 UTC
(In reply to Ed Maste from comment #3)

It's buried somewhere in here: https://opensource.apple.com/release/macos-10122.html .
Comment 6 Enji Cooper freebsd_committer freebsd_triage 2017-01-23 18:25:31 UTC
(In reply to Ngie Cooper from comment #5)

Here it is: https://opensource.apple.com/source/text_cmds/text_cmds-97/grep/ .
Comment 7 Ed Maste freebsd_committer freebsd_triage 2017-01-23 18:59:13 UTC
(In reply to Ngie Cooper from comment #6)
> https://opensource.apple.com/source/text_cmds/text_cmds-97/grep/ .

Great, thanks! It's not in the text_cmds source package prior to 10.12 and wasn't available last time I looked. I'm glad this has been addressed.
Comment 8 Kyle Evans freebsd_committer freebsd_triage 2017-01-23 19:02:27 UTC
A lot of the problems are fixed by the two or three patches I've recently submitted, a couple others (like this one) would go away fairly easily if we could not do this (block) by default: https://svnweb.freebsd.org/base/head/usr.bin/grep/Makefile?view=markup#l78

These things combined would leave us with ~4 remaining bsdgrep issues to work with, and I'm not immediately certain if those ones are really unrelated.
Comment 9 Ed Maste freebsd_committer freebsd_triage 2017-04-04 13:38:56 UTC
See review D10114 - we will switch GNU_GREP_COMPAT off by default, which will address this issue.
Comment 10 Eitan Adler freebsd_committer freebsd_triage 2018-05-20 23:50:00 UTC
For bugs matching the following conditions:
- Status == In Progress
- Assignee == "bugs@FreeBSD.org"
- Last Modified Year <= 2017

Do
- Set Status to "Open"
Comment 11 commit-hook freebsd_committer freebsd_triage 2020-12-08 14:06:04 UTC
A commit references this bug:

Author: kevans
Date: Tue Dec  8 14:05:27 UTC 2020
New revision: 368439
URL: https://svnweb.freebsd.org/changeset/base/368439

Log:
  src.opts.mk: switch to bsdgrep as /usr/bin/grep

  This has been years in the making, and we all knew it was bound to happen
  some day. Switch to the BSDL grep implementation now that it's been a
  little more thoroughly tested and theoretically supports all of the
  extensions that gnugrep in base had with our libregex(3).

  Folks shouldn't really notice much from this update; bsdgrep is slower than
  gnugrep, but this is currently the price to pay for fewer bugs. Those
  dissatisfied with the speed of grep and in need of a faster implementation
  should check out what textproc/ripgrep and textproc/the_silver_searcher
  can do for them.

  I have some WIP to make bsdgrep faster, but do not consider it a blocker
  when compared to the pros of switching now (aforementioned bugs, licensing).

  PR:		228798 (exp-run)
  PR:		128645, 156704, 166842, 166862, 180937, 193835, 201650
  PR:		232565, 242308, 246000, 251081, 191086, 194397
  Relnotes:	yes, please

Changes:
  head/share/mk/src.opts.mk