Skip to content

fix(parser): handle >= and <= operators in (( )) arithmetic commands#1023

Merged
chaliy merged 1 commit intomainfrom
fix/issue-967-arithmetic-ge-operator
Apr 2, 2026
Merged

fix(parser): handle >= and <= operators in (( )) arithmetic commands#1023
chaliy merged 1 commit intomainfrom
fix/issue-967-arithmetic-ge-operator

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 2, 2026

Summary

  • Fixed >= and <= operators in (( )) arithmetic commands always evaluating incorrectly
  • The tokenizer splits >= into RedirectOut + Word("=") and <= into RedirectIn + Word("="), which caused the (( )) parser to produce malformed expressions
  • Added lookahead in the arithmetic command parser to combine these tokens back into >= and <=
  • Also handles N>= (e.g., 3>=5) where the tokenizer produces RedirectFd(N) + Word("=...")

Why

(( 3 >= 5 )) always returned exit code 0 (true) because the = was dropped from the expression, producing 3> = 5 which was misinterpreted as an assignment returning 5 (non-zero → true).

Tests

  • Added spec tests: arith_cmd_ge_false, arith_cmd_ge_true, arith_cmd_ge_equal, arith_cmd_ge_nospace, arith_cmd_le_nospace
  • 100% bash comparison match (1697/1697)

Closes #967

The tokenizer splits >= into RedirectOut + Word("=") and <=
into RedirectIn + Word("="), causing the (( )) parser to
produce malformed expressions. Added lookahead in the arithmetic
command parser to combine these tokens back into >= and <=.

Also handles N>= (e.g., 3>=5) where the tokenizer produces
RedirectFd(N) + Word("=...").

Closes #967
@chaliy chaliy merged commit 367ab24 into main Apr 2, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-967-arithmetic-ge-operator branch April 2, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Arithmetic >= operator always returns true

1 participant