Skip to content

sed - with --posix, -e 'i\' takes the next -e as its text #688

Open

Description

@sylvestre

As a GNU extension, sed -e 'i\' -e hello uses the next -e fragment as the
text of a, i or c. With --posix, GNU sed does not join the fragments,
and an a\, i\ or c\ at the end of an -e is an incomplete command.
uutils sed joins them in both modes. The same text in one -f file (i\
followed by hello on the next line) is valid POSIX and works in both
implementations.

The GNU test compile-errors exposes this. Open PR #625 rewrites
compile_text_command_posix, but a build of it still accepts this case.

Reproduction

Rust (incorrect)

$ echo w | ./target/release/sed --posix -e 'i\' -e hello
hello
w
# Exit code: 0

GNU (correct)

$ echo w | sed --posix -e 'i\' -e hello
sed: -e expression #1, char 2: incomplete command
# Exit code: 1

$ echo w | sed -e 'i\' -e hello
hello
w
# Exit code: 0

Test

#[rstest]
#[case::append("a\\")]
#[case::insert("i\\")]
#[case::change("c\\")]
fn test_posix_text_command_stops_at_expression_end(#[case] cmd: &str) {
    new_ucmd!()
        .args(&["--posix", "-e", cmd, "-e", "second fragment"])
        .pipe_in("line\n")
        .fails()
        .code_is(1)
        .no_stdout()
        .stderr_contains("incomplete command");

    // GNU extension: without --posix the next fragment is the text.
    new_ucmd!()
        .args(&["-e", cmd, "-e", "second fragment"])
        .pipe_in("")
        .succeeds()
        .no_output();
}

Exposed by the GNU sed test suite: compile-errors.

Activity

  1. added
    bug
    good first issue
    gnu-compat
    on Nov 17, 2026
  2. added 3 commits that reference this issue on Nov 18, 2026
    168c6cf
    f94d2b4
    3ecac46
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