GNU bug report logs - #65046
Error in the "grep" documentation, section "2.1.7 Other Options": "--"

Previous Next

Package: grep;

Reported by: "Helmut Waitzmann Anti-Spam-Ticket.b.qc3c" <oe.throttle <at> xoxy.net>

Date: Fri, 4 Aug 2023 03:57:02 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#65046: closed (Error in the "grep" documentation, section
 "2.1.7 Other Options": "--")
Date: Sun, 06 Aug 2023 01:56:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Sat, 5 Aug 2023 18:54:54 -0700
with message-id <d64fb616-5a8c-2daf-d1dd-fd9c5f330c26 <at> cs.ucla.edu>
and subject line Re: bug#65046: Error in the "grep" documentation, section "2.1.7 Other Options": "--"
has caused the debbugs.gnu.org bug report #65046,
regarding Error in the "grep" documentation, section "2.1.7 Other Options": "--"
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
65046: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=65046
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Helmut Waitzmann <ml.throttle <at> xoxy.net>
To: GNU grep bug reporting team <bug-grep <at> gnu.org>
Subject: Error in the "grep" documentation, section "2.1.7 Other Options": "--"
Date: Thu, 03 Aug 2023 21:57:23 +0200
[Message part 3 (text/plain, inline)]
Hello, GNU grep bug reporting team,

in the section "2.1.7 Other Options" of the "grep" "info"
documentation (for example in
<https://www.gnu.org/software/grep/manual/html_node/Other-Options.html>),
the hint about the usage of the "--" option delimiter is wrong: 
It won't work, if the pattern "PAT" happens to start with a "-". 
And if the environment variable "POSIXLY_CORRECT" is set, it
won't even work with any pattern (except the pattern "--").


The following example may show it:


How to reproduce:  In an empty directory, run the following
commands:

  printf '%s\n' -1 +1 > -file1 &&
  printf '%s\n' -2 +2 > file2 &&
  grep '-[[:digit:]]' -- -file1 file2


Received output:

  grep: invalid option -- '['
  Usage: grep [OPTION]... PATTERN [FILE]...
  Try `grep --help' for more information.


Expected output:  According to the manual, the output should be

  -file1:-1
  file2:-2


=> The hint in the documentation is wrong:  Rather than


  ‘--’
       Delimit the option list.  Later arguments, if any, are
       treated as operands even if they begin with ‘-’.  For
-      example, ‘grep PAT -- -file1 file2’ searches for the
       pattern PAT in the files named ‘-file1’ and ‘file2’.


it should say:


  ‘--’
       Delimit the option list.  Later arguments, if any, are
       treated as operands even if they begin with ‘-’.  For
+      example, ‘grep -- PAT -file1 file2’ searches for the
       pattern PAT in the files named ‘-file1’ and ‘file2’.


(the differing lines are marked in the first position with "-"
resp. "+").


Working example:

  printf '%s\n' -1 +1 > -file1 &&
  printf '%s\n' -2 +2 > file2 &&
  grep -- '-[[:digit:]]' -file1 file2


Received output:

  -file1:-1
  file2:-2


Explanation:  As the pattern PAT shall be the first non-option
argument given to "grep", the option list delimiter "--", when
placed before the pattern in "grep"s invocation arguments list,
prevents the pattern from being misinterpreted as an option
(regardless of the POSIXLY_CORRECT environment variable being set
or unset).


Kind regards

Helmut Waitzmann
[Message part 4 (application/pgp-signature, inline)]
[Message part 5 (message/rfc822, inline)]
From: Paul Eggert <eggert <at> cs.ucla.edu>
To: "Helmut Waitzmann Anti-Spam-Ticket.b.qc3c" <oe.throttle <at> xoxy.net>
Cc: 65046-done <at> debbugs.gnu.org
Subject: Re: bug#65046: Error in the "grep" documentation, section "2.1.7
 Other Options": "--"
Date: Sat, 5 Aug 2023 18:54:54 -0700
[Message part 6 (text/plain, inline)]
Thanks for reporting that. I installed the attached patch.
[0001-doc-clarify-role.patch (text/x-patch, attachment)]

This bug report was last modified 1 year and 292 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.