Skip to content

Improve compatibility with Rust coreutils aka uutils #90

@alkuna

Description

@alkuna

Compatibility risks

tail

  • Obsolete numeric option: tail -1 (without -n) is a GNU-accepted historical shorthand. Some uutils/coreutils releases did not accept this shorthand.

  • Concatenated form: tail -n+2 (no space) is accepted by GNU tail; uutils tail historically required the POSIX form with a space (tail -n +2). Newer uutils likely accept both.

head

  • head -n 1 is standard and supported by both GNU and Rust coreutils. GNU also accepts the historical shorthand head -1 (without -n); uutils historically did not accept the obsolete numeric form in some releases.

The flow script and Makefile use -n1, so it’s fine. test.butt combines head -n1 (without space) with head -13 etc. (without -n).

Command line argument parsing in uutils

The uutils coreutils project (which includes utilities like uu_head and uu_tail) does use the clap crate for command-line argument parsing. The option -1 (and similarly -2, -3, …) is treated as a legacy POSIX/GNU shortcut, meaning:

-<number> ≡ -n <number>

This behavior is implemented intentionally in the parse_obsolete function in uucore where the digit options are intercepted and translated into -n, not provided automatically by clap. One may expect obsolete and legacy code removed in a future release.

Suggestions

  • Use tail -n 1 (with space) and tail -n +2 (with space) for maximum portability across uutils versions.
  • Prefer head -n 13 (with space) across all files for consistency and maximum portability.

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