Skip to content

[BUG] tail -n with an unparseable count silently prints 10 lines (e.g. tail -n -2) #253

Done

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

built from main @ d4c57a7

Language Runtime Version

Rust 1.100.0

Operating System

Amazon Linux 2023 (aarch64)

Installation Method

built from source

Steps to Reproduce

printf '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n' | tail -n -2
printf '1\n2\n3\n' | tail -n abc; echo rc=$?

Expected Behavior

Match GNU tail: tail -n -2 prints the last 2 lines (11, 12) — a leading - is the same as no sign. tail -n abc errors (invalid number of lines) and exits 1.

Actual Behavior

tail -n -2 prints the last 10 lines (3 … 12). tail -n abc prints the whole input and exits 0. Any count that fails to parse is silently replaced with a default, so an agent gets a wrong answer with no error.

Possible Solution

src/commands/tail.rs:25 — count = val.parse().unwrap_or(10); (and rest.parse().unwrap_or(1) on line 23 for +N). Strip an optional leading - and propagate the parse error with ?, the way head does after #218 (signed_count in src/commands/head.rs).

Related Issues

Found while reviewing #218 (part of #207). Pre-existing on main, not introduced by that PR.

Activity

  1. added
    bug
    rust
    on Nov 12, 2026
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

    bugrust

    Type

    No type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions