[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grep branch, master, updated. v3.7-51-gefe1e15

From: Paul Eggert
Subject: grep branch, master, updated. v3.7-51-gefe1e15
Date: Sun, 27 Feb 2022 18:18:02 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  efe1e1543c409504752f8d240d3ea41af3b8fddf (commit)
      from  1580562d51aa3d4ce320906ddb6b6a344c0f47b4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------

commit efe1e1543c409504752f8d240d3ea41af3b8fddf
Author: Paul Eggert <>
Date:   Sun Feb 27 15:15:51 2022 -0800

    doc: more on leading ‘-’
    * doc/grep.texi (Usage): Expand on leading ‘-’ problems (Bug#54174).

diff --git a/doc/grep.texi b/doc/grep.texi
index ebbefda..f0ea1c3 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -1719,25 +1719,39 @@ grep -r --include='*.c' 'hello' /home/gigi
 What if a pattern or file has a leading @samp{-}?
+For example:
+grep "$pattern" *
+@end example
+can behave unexpectedly if the value of @samp{pattern} begins with @samp{-},
+or if the @samp{*} expands to a file name with leading @samp{-}.
+To avoid the problem, you can use @option{-e} for patterns and leading
+@samp{./} for files:
-grep -- '--cut here--' *
+grep -e "$pattern" ./*
 @end example
-searches for all lines matching @samp{--cut here--}.
-Without @option{--},
-@command{grep} would attempt to parse @samp{--cut here--} as a list of
-options, and there would be similar problems with any file names
-beginning with @samp{-}.
+searches for all lines matching the pattern in all the working
+directory's files whose names do not begin with @samp{.}.
+Without the @option{-e}, @command{grep} might treat the pattern as an
+option if it begins with @samp{-}.  Without the @samp{./}, there might
+be similar problems with file names beginning with @samp{-}.
-Alternatively, you can prevent misinterpretation of leading @samp{-}
-by using @option{-e} for patterns and leading @samp{./} for files:
+Alternatively, you can use @samp{--} before the pattern and file names:
-grep -e '--cut here--' ./*
+grep -- "$pattern" *
 @end example
+This also fixes the problem, except that if there is a file named @samp{-},
+@command{grep} misinterprets the @samp{-} as standard input.
 Suppose I want to search for a whole word, not a part of a word?


Summary of changes:
 doc/grep.texi | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]