Project

General

Profile

Bug #12273

Forward slash foils grep -w

Added by Jason King 2 months ago. Updated 2 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
cmd - userland programs
Start date:
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:

Description

Investigating #12181, comparing the behavior of FreeBSD and GNU grep -w to illumos grep -w, it appears the leading / breaks things:

Illumos:

root@pi:/ws/illumos-gate/usr/src/lib/libc/port/regex (multilist)# echo "foo bar baz" | grep -w bar
foo bar baz
root@pi:/ws/illumos-gate/usr/src/lib/libc/port/regex (multilist)# echo "foo bar baz" | grep -w baz
foo bar baz
root@pi:/ws/illumos-gate/usr/src/lib/libc/port/regex (multilist)# echo "foo bar baz" | grep -w foo
foo bar baz
root@pi:/ws/illumos-gate/usr/src/lib/libc/port/regex (multilist)# echo "/foo bar baz" | grep -w /foo
root@pi:/ws/illumos-gate/usr/src/lib/libc/port/regex (multilist)# echo "/foo bar baz" | /usr/gnu/bin/grep -w /foo
/foo bar baz

On FreeBSD:

[jbk@syzygy ~]$ echo "foo bar baz" | grep -w bar
foo bar baz
[jbk@syzygy ~]$ echo "foo bar baz" | grep -w baz
foo bar baz
[jbk@syzygy ~]$ echo "foo bar baz" | grep -w foo
foo bar baz
[jbk@syzygy ~]$ echo "/foo bar baz" | grep -w foo
/foo bar baz

Related issues

Related to illumos gate - Bug #12181: zvol tests should avoid grep -wClosed

Actions

History

#1

Updated by Jason King 2 months ago

  • Description updated (diff)
#2

Updated by Jason King 2 months ago

To add more confusion: illumos grep(1) defines grep -w pattern as equivalent to grep '\<pattern\>' (this is how it's also implemented internally), however BSD grep(1) does not states this (nor does it implement -w in that manner). In fact grep \<pattern\> has the same behavior on BSD and illumos, including when pattern begins with a /. So it's still unclear what the correct behavior should be.

#3

Updated by Jason King 2 months ago

  • Related to Bug #12181: zvol tests should avoid grep -w added

Also available in: Atom PDF