Skip to content

[bug] Negative shift count in arithmetic is treated as a syntax error ($((8>>-1))) #1135

Closed

Description

@caomengxuan666

[bug] Negative shift count in arithmetic is treated as a syntax error ($((8>>-1)))

echo $((8>>-1)); echo rc=$?
# GNU bash 5.3.20: 0, rc=0  (shift count is taken modulo the word size)
# rubash / niu:     '8>>-1: arithmetic syntax error: operand expected', the whole expansion fails, rc=1

Expected (GNU bash 5.3.20): prints 0, exit status 0. 8<<-1 behaves the same in GNU.
Actual (rubash): arithmetic syntax error, no output, exit status 1.

Computed shift counts that can go negative (a common bit-manipulation pattern) abort expansions that GNU evaluates fine.

Env: rubash master 493ebb2 / niubash 1.4.4 (niu, master 953f513, embeds rubash 493ebb2), Linux x86_64, GNU bash 5.3.20 x86_64-pc-linux-gnu as oracle. Also reproduces in niu (same engine).

Activity

  1. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    FIXED-BY-#1181 — verified on master (263ce53f). Commit bb3a110.

    echo $((8>>-1)) → 0, rc=0; 8<<-1 same. Identical to GNU 5.3.20 (shift count wraps like C).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions