aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtests/grep.test2
-rw-r--r--toys/posix/grep.c7
2 files changed, 5 insertions, 4 deletions
diff --git a/tests/grep.test b/tests/grep.test
index 798a9c6a..0e0f3c47 100755
--- a/tests/grep.test
+++ b/tests/grep.test
@@ -90,6 +90,8 @@ testing "-Fx ''" "grep -Fx '' input" "" "one one one\n" ""
testing "-F ''" "grep -F '' input" "one one one\n" "one one one\n" ""
testing "-F -e blah -e ''" "grep -F -e blah -e '' input" "one one one\n" \
"one one one\n" ""
+testing "-Fxv -e subset" "grep -Fxv -e bbswitch-dkms -e dkms" "" "" \
+ "bbswitch-dkms\n"
testing "-e blah -e ''" "grep -e blah -e '' input" "one one one\n" \
"one one one\n" ""
testing "-w ''" "grep -w '' input" "" "one one one\n" ""
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index c88d4c65..5afe38ca 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -173,14 +173,13 @@ static void do_grep(int fd, char *name)
for (seek = TT.e; seek; seek = seek->next) {
if (FLAG(x)) {
- if ((FLAG(i) ? strcasecmp : strcmp)(seek->arg, line)) s = line;
+ if (!(FLAG(i) ? strcasecmp : strcmp)(seek->arg, line)) s = line;
} else if (!*seek->arg) {
seek = &fseek;
fseek.arg = s = line;
- break;
- }
- if (FLAG(i)) s = strcasestr(line, seek->arg);
+ } else if (FLAG(i)) s = strcasestr(line, seek->arg);
else s = strstr(line, seek->arg);
+
if (s) break;
}