Skip to content

-l and -L are not mutually exclusive last-wins like GNU #26

Closed

Description

@sylvestre

-l (--files-with-matches) and -L (--files-without-match) are opposites. GNU treats them as mutually exclusive with last-one-wins semantics. uu_grep keeps both flags independently active and always lets -l win, so -l -L (with -l first) diverges.

Found by the differential fuzzer (fuzz_grep).

Rust (incorrect)

$ printf 'match5here\n' > /tmp/p.txt
$ ./target/release/grep -e 5 -l -L /tmp/p.txt
/tmp/p.txt
# Exit code: 0

GNU (correct)

$ printf 'match5here\n' > /tmp/p.txt
$ LC_ALL=C /usr/bin/grep -e 5 -l -L /tmp/p.txt
# Output: (none — last flag is -L, and the file *does* match, so it is not listed)
# Exit code: 0

With the order reversed (-L -l, last flag -l) both print the filename, confirming GNU's last-wins rule. uu_grep prints the filename in both orders.

Activity

  1. wondr-wclabs commented on Jun 5, 2026

    @wondr-wclabs
    Contributor

    I checked this against current upstream/main, and it looks fixed already rather than needing another code change.

    The current parser defines -l and -L with reciprocal Clap overrides, and tests/test_grep.rs already has files_with_and_without_matches_mutually_exclusive covering both orders. The original repro now matches GNU last-wins behavior for me: grep -e 5 -l -L /tmp/p.txt exits 0 with no output, while grep -e 5 -L -l /tmp/p.txt prints the filename.

    I also ran cargo test files_with_and_without_matches_mutually_exclusive -- --nocapture, and that targeted test passes. Unless there is another ordering/alias variant you had in mind, I think this one can be closed as already resolved.

  2. sylvestre commented on Jun 5, 2026

    @sylvestre
    SponsorContributorAuthor

    it has been fixed by #30 not closed

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

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions