Skip to content

head: missing support for implicit -n (e.g. head -5) #171

@AlexandreYang

Description

@AlexandreYang

Bug

Image

head does not support the shorthand form head -5 (passing a number directly without -n), while tail handles it correctly.

Expected behavior (bash-compatible):

$ echo -e "1\n2\n3\n4\n5\n6" | head -5
1
2
3
4
5

Actual behavior:
head -5 likely returns an "unknown flag" or similar error.

Source

Reported internally via Slack (2026-04-02).

Fix

When parsing flags in the head builtin, handle the case where a bare numeric argument (e.g. -5, -42) is passed — treating it as equivalent to -n 5 / -n 42. This matches POSIX/bash/GNU behaviour.

tail already implements this correctly and can serve as a reference.

Metadata

Metadata

Assignees

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