From fb3c380d070bb310352038a3a29de8506e6ff5af Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 21 Sep 2021 15:04:30 -0700 Subject: [PATCH] grep: Implement -L. --- tests/grep.test | 1 + toys/posix/grep.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/grep.test b/tests/grep.test index 215491c2..7f882919 100755 --- a/tests/grep.test +++ b/tests/grep.test @@ -13,6 +13,7 @@ echo -e "this is test" > foo echo -e "this is test2" > foo2 echo -e "this is foo3" > foo3 testing "-l" "grep -l test foo foo2 foo3" "foo\nfoo2\n" "" "" +testing "-L" "grep -L test foo foo2 foo3" "foo3\n" "" "" rm foo foo2 foo3 testing "-q" "grep -q test input && echo yes" "yes\n" "this is a test\n" "" diff --git a/toys/posix/grep.c b/toys/posix/grep.c index 8eb3c03a..37e2083d 100644 --- a/toys/posix/grep.c +++ b/toys/posix/grep.c @@ -10,7 +10,7 @@ * echo hello | grep -f = TT.m) break; } + if (FLAG(L)) { + xprintf("%s%c", name, TT.outdelim); + return; + } + if (FLAG(c)) outline(0, ':', name, mcount, 0, 1); // loopfiles will also close the fd, but this frees an (opaque) struct. -- 2.39.2