Skip to content

Exit/return codes not truncated to 8-bit range #356

@chaliy

Description

@chaliy

Description

Bash truncates exit and return codes to an unsigned 8-bit range (0-255). Bashkit does not perform this truncation, passing through values > 255 or negative values directly.

Scope

  • exit 256 should produce exit code 0 (256 mod 256)
  • exit 257 should produce exit code 1
  • exit -1 should produce exit code 255 (two's complement wrap)
  • exit -2 should produce exit code 254
  • Same behavior for return in functions
  • '' as a command should fail (exit code 127), not succeed

Repro

f() { return 256; }; f; echo $?
# bashkit outputs: 256 (wrong)
# expected: 0

f() { return -1; }; f; echo $?
# bashkit outputs: -1 (wrong)
# expected: 255

if ''; then echo TRUE; else echo FALSE; fi
# bashkit outputs: TRUE (wrong)
# expected: FALSE

Test coverage

9 skipped tests in crates/bashkit/tests/spec_cases/bash/exit-status.test.sh (PR #351).

Oils reference: https://github.com/oilshell/oil/blob/master/spec/exit-status.test.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions