Skip to content

grep - an unknown option prints clap's error: ... block (and Usage: grep-usage) instead of grep: ... #214

Description

@sylvestre

For an unknown option GNU grep prints one line prefixed with the program name
(grep: unrecognized option '--frobnicate' or grep: invalid option -- 'j'), then
Usage: grep [OPTION]... PATTERNS [FILE]... and Try 'grep --help' for more information.
uu_grep prints clap's multi-line block that starts with error:, adds a tip:, and its
usage line is the unresolved placeholder Usage: grep-usage. The exit status (2) matches.

Scripts that derive the program name from the first PROG: of this message break. The GNU
test filename-lineno.pl does exactly that (it runs grep --no-such-option and keeps the text
before the first :), gets error, and then every sub-test runs a command called error
(exit 127). Once that is fixed the same test still fails on the known issues #179 and #185
and on the retry-limit panic.

Reproduction

Rust (incorrect)

$ ./target/release/grep --frobnicate x </dev/null
error: unexpected argument '--frobnicate' found

  tip: to pass '--frobnicate' as a value, use '-- --frobnicate'

Usage: grep-usage

For more information, try '--help'.
# Exit code: 2

$ ./target/release/grep -j x </dev/null
error: unexpected argument '-j' found
...
Usage: grep-usage
...
# Exit code: 2

GNU (correct)

$ LC_ALL=C /usr/bin/grep --frobnicate x </dev/null
/usr/bin/grep: unrecognized option '--frobnicate'
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
# Exit code: 2

$ LC_ALL=C /usr/bin/grep -j x </dev/null
/usr/bin/grep: invalid option -- 'j'
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
# Exit code: 2

Test

#[test]
fn unknown_option_diagnostic() {
    let (_s, mut c) = ucmd();
    c.args(&["--no-such-flag-here", "q"])
        .fails_with_code(2)
        .no_stdout()
        .stderr_contains("grep: unrecognized option '--no-such-flag-here'")
        .stderr_does_not_contain("grep-usage");

    let (_s, mut c) = ucmd();
    c.args(&["-j", "q"])
        .fails_with_code(2)
        .stderr_contains("grep: invalid option -- 'j'");
}

Exposed by the GNU grep test suite: filename-lineno.pl.

Activity

  1. added
    bug
    good first issue
    gnu-compat
    on Nov 17, 2026
  2. added 6 commits that reference this issue on Nov 22, 2026
    ba8add9
    6ce10bd
    0c07af7
    27f53c5
    c8d6e80
    5e0782f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggnu-compatgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions