[Top][All Lists]

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

grep branch, master, updated. v3.7-50-g1580562

From: Paul Eggert
Subject: grep branch, master, updated. v3.7-50-g1580562
Date: Thu, 24 Feb 2022 14:08:05 -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  1580562d51aa3d4ce320906ddb6b6a344c0f47b4 (commit)
      from  c128fa57c6cb8d7526b38dffa25b435dca396b7e (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 1580562d51aa3d4ce320906ddb6b6a344c0f47b4
Author: Paul Eggert <>
Date:   Thu Feb 24 11:07:14 2022 -0800

    doc: mention issues with set -e
    * doc/grep.texi (Usage, Performance): Mention early exits (Bug#54035).

diff --git a/doc/grep.texi b/doc/grep.texi
index 37ef839..ebbefda 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -1862,6 +1862,22 @@ Use the special file name @samp{-}:
 cat /etc/passwd | grep 'alain' - /etc/motd
 @end example
+Why can't I combine the shell's @samp{set -e} with @command{grep}?
+The @command{grep} command follows the convention of programs like
+@command{cmp} and @command{diff} where an exit status of 1 is not an
+error.  The shell command @samp{set -e} causes the shell to exit if
+any subcommand exits with nonzero status, and this will cause the
+shell to exit merely because @command{grep} selected no lines,
+which is ordinarily not what you want.
+There is a related problem with Bash's @command{set -e -o pipefail}.
+Since @command{grep} does not always read all its input, a command
+outputting to a pipe read by @command{grep} can fail when
+@command{grep} exits before reading all its input, and the command's
+failure can cause Bash to exit.
 Why is this back-reference failing?
@@ -1998,6 +2014,14 @@ needing to read the zeros.  This optimization is not 
available if the
 Directory Selection}), unless the @option{-z} (@option{--null-data})
 option is also used (@pxref{Other Options}).
+@cindex pipelines and reading
+For efficiency @command{grep} does not always read all its input.
+For example, the shell command @samp{sed '/^...$/d' | grep -q X} can
+cause @command{grep} to exit immediately after reading a line
+containing @samp{X}, without bothering to read the rest of its input data.
+This in turn can cause @command{sed} to exit with a nonzero status because
+@command{sed} cannot write to its output pipe after @command{grep} exits.
 For more about the algorithms used by @command{grep} and about
 related string matching algorithms, see:


Summary of changes:
 doc/grep.texi | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)


reply via email to

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