Repository navigation
Done
Labels
gnu-compatBehaviour differs from GNUgood first issueGood for newcomersoss-scannerFound by Anthropic's OSS Scanner
Description
GNU grep (getopt_long) accepts any unambiguous prefix of a long option: --cou for
--count, --reg=foo for --regexp=foo, --max 1 for --max-count 1, --ignore for
--ignore-case. An ambiguous prefix (--co) is an error. uu_grep only accepts the exact
names, so every abbreviation fails with unexpected argument and exit 2, and scripts or
habits that rely on GNU's abbreviations break.
Reproduction
Rust (incorrect)
$ printf 'a\nb\n' | ./target/release/grep --cou a
error: unexpected argument '--cou' found
tip: a similar argument exists: '--count'
Usage: grep-usage
For more information, try '--help'.
# Exit code: 2
$ printf 'a\nb\n' | ./target/release/grep --reg=a
error: unexpected argument '--reg' found
tip: a similar argument exists: '--regexp'
...
# Exit code: 2GNU (correct)
$ printf 'a\nb\n' | LC_ALL=C /usr/bin/grep --cou a
1
# Exit code: 0
$ printf 'a\nb\n' | LC_ALL=C /usr/bin/grep --reg=a
a
# Exit code: 0
$ printf 'a\nb\n' | LC_ALL=C /usr/bin/grep --co a
/usr/bin/grep: option '--co' is ambiguous; possibilities: '--context' '--color' '--colour' '--count'
Usage: grep [OPTION]... PATTERNS [FILE]...
Try 'grep --help' for more information.
# Exit code: 2Root cause
The Command built in uu_app() (src/lib.rs:493-502) never enables clap's long-option
inference:
Command::new("grep")
.version(env!("CARGO_PKG_VERSION"))
.about("Search for PATTERNS in each FILE.")
.disable_help_flag(true)
.disable_version_flag(true)
...
.args_override_self(true)Test
#[test]
fn abbreviated_long_options() {
let (_s, mut c) = ucmd();
c.args(&["--cou", "a"]).pipe_in("a\nb\na\n").succeeds().stdout_only("2\n");
let (_s, mut c) = ucmd();
c.args(&["--reg=b"]).pipe_in("a\nb\n").succeeds().stdout_only("b\n");
let (_s, mut c) = ucmd();
c.args(&["--max", "1", "a"]).pipe_in("a\na\n").succeeds().stdout_only("a\n");
let (_s, mut c) = ucmd();
c.args(&["--reg", "-7"]).pipe_in("-7\nx\n").succeeds().stdout_only("-7\n");
// Ambiguous prefix stays a usage error.
let (_s, mut c) = ucmd();
c.args(&["--co", "a"]).pipe_in("a\n").fails_with_code(2);
}Reported by Anthropic's OSS Scanner (ANT-2026-MEA9YMEZ).
Metadata
Metadata
Assignees
Labels
gnu-compatBehaviour differs from GNUgood first issueGood for newcomersoss-scannerFound by Anthropic's OSS Scanner
Activity