Skip to content

[BUG] [ / test integer operators read an empty or non-numeric operand as 0 ([ "" -lt 3 ] is true) #334

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from 55d7816; main @ c28e1fb only adds whoami on top)
  • 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

55d7816 (--version prints 0.0.0)

Language Runtime Version

Rust 1.100.0

Operating System

Linux 6.18 (aarch64)

Installation Method

built from source

Steps to Reproduce

strands-shell -c 'e=; [ "$e" -lt 3 ]; echo "rc=$?"'
strands-shell -c '[ abc -eq 0 ]; echo "rc=$?"'

Expected Behavior

Same as bash: an error on stderr and status 2, so the condition is not taken.

bash: line 1: [: : integer expression expected
rc=2
bash: line 1: [: abc: integer expression expected
rc=2

Actual Behavior

Both print rc=0 with nothing on stderr. The operand is read as 0, so the test is true.

Additional Context

Found while reviewing #332. It is not caused by that PR: both commands give rc=0 on its base 55d7816. That PR does widen the reach, because a quoted unset variable is now kept as an empty operand instead of being dropped:

unset n; while [ "$n" -lt 2 ]; do echo "loop [$n]"; n=$((n+1)); done; echo end
Output
bash 5.2.15 error message, then end
base 55d7816 end (the operand was dropped, leaving [ -lt 2 ])
#332 head 3abe869 loop [], loop [1], end

I ran debug builds through -c only.

Possible Solution

src/builtins/test.rs:220:

fn num(s: &str) -> i64 {
    s.parse().unwrap_or(0)
}

Returning an error for an operand that does not parse, and having test report it with status 2, would match bash. That is the same status-2 path #321 asks for when an operand is missing. I have not written or tested a fix.

Related Issues

#321, #332, #299

Activity

  1. added
    bug
    on Nov 19, 2026
  2. added a commit that references this issue on Nov 21, 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

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions