Skip to content

sed - GNU options --file, --line-length, --zero-terminated and -b/--binary are rejected #645

Open

Description

@sylvestre

Known: #552 (open PR) — #552

GNU sed documents several option spellings that uutils sed does not accept. Each one fails
during argument parsing with unexpected argument and exit status 1:

GNU spelling uutils equivalent today
--file=SCRIPT -f / --script-file
--line-length=N -l / --length
--zero-terminated -z / --null-data
-b / --binary (none; a no-op on POSIX systems in GNU)

Reproduction

Rust (incorrect)

$ echo p > scr.sed
$ printf 'a\n' | ./target/release/sed --file=scr.sed
error: unexpected argument '--file' found

  tip: a similar argument exists: '--silent'

Usage: sed [OPTION]... [script] [file]...

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

$ printf 'a\n' | ./target/release/sed -n --line-length=5 l
error: unexpected argument '--line-length' found
...
# Exit code: 1

$ printf 'a\n' | ./target/release/sed -b p
error: unexpected argument '-b' found
...
# Exit code: 1

GNU (correct)

$ printf 'a\n' | /usr/bin/sed --file=scr.sed
a
a
# Exit code: 0

$ printf 'a\n' | /usr/bin/sed -n --line-length=5 l
a$
# Exit code: 0

$ printf 'a\n' | /usr/bin/sed -b p
a
a
# Exit code: 0

--zero-terminated fails the same way. (-z itself is accepted but currently ignored; that is
tracked separately in #530 / #585 and is out of scope here.)

Root cause

The clap definitions in uu_app() (src/sed/mod.rs:209-249) only declare the uutils spellings:

Arg::new("script-file")
    .short('f')
    .long("script-file")
...
arg!(-l --length <NUM> "Specify the 'l' command line-wrap length.")
...
Arg::new("null-data")
    .short('z')
    .long("null-data")

Test

#[rstest]
#[case::binary_short("-b")]
#[case::binary_long("--binary")]
#[case::zero_terminated("--zero-terminated")]
fn test_gnu_option_spellings_accepted(#[case] option: &str) {
    new_ucmd!().args(&[option, "p"]).pipe_in("a").succeeds();
}

#[test]
fn test_file_long_option() {
    let mut script = NamedTempFile::new().unwrap();
    script.write_all(b"s/a/b/\n").unwrap();
    new_ucmd!()
        .arg(format!("--file={}", script.path().display()))
        .pipe_in("a\n")
        .succeeds()
        .stdout_is("b\n");
}

#[test]
fn test_line_length_long_option() {
    new_ucmd!()
        .args(&["-n", "--line-length=5", "l"])
        .pipe_in("abcdefgh\n")
        .succeeds()
        .stdout_is("abcd\\\nefgh$\n");
}

Reported by Anthropic's OSS Scanner (ANT-2026-0NWFERRZ).

Activity

  1. added
    bug
    good first issue
    oss-scanner
    gnu-compat
    on Nov 9, 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 issueoss-scanner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions