aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2021-02-04 21:35:58 +0000
committerKyle Evans <kevans@FreeBSD.org>2021-02-11 15:20:18 +0000
commit1db55207b66154de839e515046736cd06e50fe30 (patch)
tree55d92a0406ed71d1a1101d855330a1b9b73d3a35
parent92ddb6090b0c5091a64855a514676a452c10750c (diff)
downloadsrc-1db55207b66154de839e515046736cd06e50fe30.tar.gz
src-1db55207b66154de839e515046736cd06e50fe30.zip
grep: turn off -w if -x is specified
-x overcomes -w in gnugrep, and it should here as well. Flip it off as needed to avoid confusing other parts of grep. (cherry picked from commit 2373acbbb77d694b997d90f3251810c6edf5d6d8)
-rw-r--r--usr.bin/grep/grep.15
-rw-r--r--usr.bin/grep/grep.c4
2 files changed, 8 insertions, 1 deletions
diff --git a/usr.bin/grep/grep.1 b/usr.bin/grep/grep.1
index b6f6e6f31d22..9aac1cc6ca92 100644
--- a/usr.bin/grep/grep.1
+++ b/usr.bin/grep/grep.1
@@ -30,7 +30,7 @@
.\"
.\" @(#)grep.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd August 7, 2020
+.Dd February 11, 2021
.Dt GREP 1
.Os
.Sh NAME
@@ -405,6 +405,9 @@ and
.Sq [[:>:]] ;
see
.Xr re_format 7 ) .
+This option has no effect if
+.Fl x
+is also specified.
.It Fl x , Fl Fl line-regexp
Only input lines selected against an entire fixed string or regular
expression are considered to be matching lines.
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index cc860b0566d4..a9c67c268b47 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -635,6 +635,10 @@ main(int argc, char *argv[])
aargc -= optind;
aargv += optind;
+ /* xflag takes precedence, don't confuse the matching bits. */
+ if (wflag && xflag)
+ wflag = false;
+
/* Fail if we don't have any pattern */
if (aargc == 0 && needpattern)
usage();