Date: Wed, 11 Apr 2012 13:49:56 GMT From: Jim Pryor <dubiousjim@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/166842: bsdgrep inconsistently handles ^ in non-anchoring positions Message-ID: <201204111349.q3BDnuFU085523@red.freebsd.org> Resent-Message-ID: <201204111350.q3BDoC8o066859@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 166842 >Category: bin >Synopsis: bsdgrep inconsistently handles ^ in non-anchoring positions >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Apr 11 13:50:12 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Jim Pryor >Release: 9.0-PRELEASE >Organization: >Environment: FreeBSD vaio.jimpryor.net 9.0-PRERELEASE FreeBSD 9.0-PRERELEASE #0: Tue Nov 29 02:45:33 EST 2011 root@vaio.jimpryor.net:/usr/obj/usr/src/sys/MINE amd64 >Description: version line: /* $FreeBSD: src/usr.bin/grep/grep.c,v 1.11.2.3 2011/10/20 16:08:11 gabor Exp $ According to the POSIX-2008 standard, "^" and "$" should be ordinary characters in BREs (basic regexs) when they're not in anchoring positions (as contrasted to EREs, where they should always be anchors). Hence: $ printf 'a^b$c' | grep -o 'a^b' should match, and it does when I use Gnu grep (on Linux), and using BusyBox grep (again on Linux, built against uClibc). But it doesn't using the described version of FreeBSD grep. Curiously though: $ printf 'a^b$c' | grep -o '[a]^b' will match. And so too will 'b$c'. One can't portably rely on '\^' here to specify the literal '^', because POSIX-2008 says that '^' in non-anchoring positions is not special in BREs, and that the combination of '\' and a non-special character is undefined. Of course, neither can one use '[^]'. >How-To-Repeat: See above. >Fix: >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204111349.q3BDnuFU085523>