Skip to content

l command: the wrap width comes from the terminal size, and -l is ignored #551

Description

@SichenLiang

The wrap width used by the l command does not come from the -l option or from its documented default. It comes from the width of the terminal the process happens to be running in, and falls back to 60 when there is no terminal. The same command on the same input therefore produces different bytes depending on where the output goes, and changes when the window is resized.

Tested with uutils sed 0.2.0 built from main at 77f442d, against GNU sed 4.9, under LC_ALL=C.

Measured under a pty of an explicit width, input 200 x, length of the first output line:

terminal columns 20 40 80 120 200
GNU sed 4.9 70 70 70 70 70
uutils sed 20 40 80 120 200

-l N is parsed and then ignored:

$ printf 'aaaaaaaaaa\n' | sed -n -l 5 l
aaaa\
aaaa\
aa$

$ printf 'aaaaaaaaaa\n' | ./target/release/sed -n -l 5 l
aaaaaaaaaa$

-l 5, -l 0 and -l 200 all produce the same output.

l 0 folds after every character:

$ echo abc | sed -n 'l 0'
abc$

$ echo abc | ./target/release/sed -n 'l 0'
\
a\
b\
c$

With no terminal, the default width is 60 rather than 70:

$ printf 'a%.0s' {1..70} | sed -n l
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
a$

$ printf 'a%.0s' {1..70} | ./target/release/sed -n l
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\
aaaaaaaaaaa$

The GNU sed manual, on -l N: "A length of 0 (zero) means to never wrap long lines. If not specified, it is taken to be 70." On the l n argument: "a length of 0 (zero) means to never wrap long lines. If omitted, the default as specified on the command line is used."

compile_number_command in src/sed/compiler.rs stores output_width() when l has no numeric argument, and output_width() reads terminal_size(). The value from -l is already computed correctly into ProcessingContext::length in src/sed/mod.rs (defaulting to 70) and is never read.

I have a fix for this and will open a PR.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions