Skip to content

head emits an extra trailing blank line on its default line count #80

Description

@davydog187

head emits an extra trailing blank line on its default line count.

# /f = "x\n"
$ head /f
x
                 <- extra blank line; GNU prints "x\n"

Raw bytes:

command just_bash GNU
head /f "x\n\n" "x\n"
echo x | head "x\n\n" "x\n"
head /f /g "==> /f <==\nx\n\n\n==> /g <==\nhi\n\n" "==> /f <==\nx\n\n==> /g <==\nhi\n"

It is specific to the default line count. The explicit form is correct:

head -n1 /f        ->  "x\n"                                        matches GNU
head -n1 - /f      ->  "==> standard input <==\nSSS\n\n==> /f <==\nFFF\n"   matches GNU

So the bug is in the default-count path of take_content / format_head_output in
lib/just_bash/commands/head.ex, not in the multi-file separator logic — the multi-file case just makes
it visible twice.

Anything byte-comparing head output gets a spurious diff, and x=$(head f) picks up the extra newline
before command substitution strips it (so that particular spelling hides it, which is part of why it has
survived).

Worth checking tail for the same shape, since the two share their default-count handling.


Pre-existing. Reproduced byte-identically at bb55214 and d59d84d, and unrelated to the - operand
work in PR #74 (head.ex's take_content/format_head_output were not modified there), which is why it
was deferred.

Found by an independent verification pass while working #70.

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