Skip to content

grep - -L with -m 0 or -v '' prints nothing; GNU still lists every file #213

Open

Description

@sylvestre

When no line can be selected (-m 0, or -v with an empty pattern) uu_grep exits 1 before
opening any file. That is right for plain output, -c, -l and -q, but not for
-L/--files-without-match: every file then has no selected line, and GNU grep lists each
readable file (and still reports files it cannot open). uu_grep prints nothing.

Exposed by the GNU test skip-read (grep -L -m0 y /dev/null and grep -L -v "" /dev/null must print /dev/null, with -G, -E and -F).

Reproduction

$ printf 'red\n' > colors

Rust (incorrect)

$ ./target/release/grep -L -m 0 red colors
# Output: (none)
# Exit code: 1

$ ./target/release/grep -L -v -e '' colors
# Output: (none)
# Exit code: 1

GNU (correct)

$ LC_ALL=C /usr/bin/grep -L -m 0 red colors
colors
# Exit code: 1

$ LC_ALL=C /usr/bin/grep -L -v -e '' colors
colors
# Exit code: 1

$ LC_ALL=C /usr/bin/grep -L -m 0 red colors nosuch
colors
/usr/bin/grep: nosuch: No such file or directory
# Exit code: 2

Test

#[test]
fn files_without_match_with_nothing_selectable() {
    for args in [&["-L", "-m", "0", "pine"][..], &["-L", "-v", "-e", ""][..]] {
        let (scene, mut c) = ucmd();
        scene.fixtures.write("trees.txt", "pine\noak\n");
        c.args(args)
            .arg("trees.txt")
            .fails_with_code(1)
            .stdout_only("trees.txt\n");
    }
}

Exposed by the GNU grep test suite: skip-read.

Activity

  1. added
    bug
    good first issue
    gnu-compat
    on Nov 17, 2026
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