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.
This commit is contained in:
Kyle Evans 2021-02-04 15:35:58 -06:00
parent f823c6dc73
commit 2373acbbb7
2 changed files with 8 additions and 1 deletions

View File

@ -30,7 +30,7 @@
.\"
.\" @(#)grep.1 8.3 (Berkeley) 4/18/94
.\"
.Dd November 19, 2020
.Dd February 4, 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.

View File

@ -630,6 +630,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();