diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 6037a66224..38f6b14694 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -723,7 +723,9 @@ pub fn uu_app() -> Command { .value_name("delimit-method") .num_args(0..=1) .default_missing_value("none") - .require_equals(true), + .require_equals(true) + // GNU accepts a repeated -D/--all-repeated and uses the last one. + .overrides_with(options::ALL_REPEATED), ) .arg( Arg::new(options::GROUP) diff --git a/tests/by-util/test_uniq.rs b/tests/by-util/test_uniq.rs index 8e940a743c..58a9bff062 100644 --- a/tests/by-util/test_uniq.rs +++ b/tests/by-util/test_uniq.rs @@ -162,6 +162,22 @@ fn test_stdin_all_repeated() { .stdout_is_fixture("sorted-all-repeated.expected"); } +#[test] +fn test_all_repeated_repeated_last_wins() { + // GNU uniq accepts a repeated -D/--all-repeated and uses the last occurrence, + // instead of rejecting the second one. + new_ucmd!() + .args(&["-D", "--all-repeated=separate"]) + .pipe_in("a\na\nb\nb\nc\n") + .succeeds() + .stdout_is("a\na\n\nb\nb\n"); + new_ucmd!() + .args(&["-D", "-D"]) + .pipe_in("a\na\n") + .succeeds() + .stdout_is("a\na\n"); +} + #[test] fn test_all_repeated_followed_by_filename() { let filename = "test.txt";