Skip to content

fix(interpreter): named file descriptors ({var}>file) and <> like bash - #2624

Merged
chaliy merged 4 commits into
mainfrom
claude/project-thread-eafupr-bb-namedfd
Oct 8, 2026
Merged

chaliy merged 4 commits into
mainfrom
claude/project-thread-eafupr-bb-namedfd

Conversation

@chaliy

@chaliy chaliy commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

Named file descriptors now behave like bash 5.2:

  • {var} works with every redirect form (>, <, >>, <>, <<<, <<, >&N, <&N) on any simple or compound command, and the fd stays open afterwards.
  • Allocation takes the lowest free fd from 10 up and ignores the variable's old value. Locals and array elements work; a readonly variable fails.
  • {var}>&- closes the fd, and a closed fd is reused.
  • >&N / <&N to a closed fd prints Bad file descriptor with status 1; a dup to a word prints ambiguous redirect.
  • The lexer accepts multi-digit fds (10>x), <> and N<<<word, and declare -f prints {var} redirects back.
  • exec applies its redirects in order and no longer applies them a second time, which fixes exec 1>&3 3>&-.

Fds stay virtual and per interpreter; no host fds are touched.

Why

BashBox corpus batch: all 17 skipped cases in bashbox-named-fd.test.sh now pass, plus readwrite_redirect_opens_file (<> used to be a parse error).

Before / After

exec {fd}>f; echo $fd; echo hi >&$fd; exec {fd}>&-; cat f; echo x {o}>g; echo $o; echo hi >&9; echo rc=$?

before: "" / "hi" / "" / rc=0       # no fd allocated, x went to g, >&9 silently succeeded
after:  10 / hi / x / 10 / bash: 9: Bad file descriptor / rc=1   # matches bash 5.2

Risk

  • Medium: the redirect path is shared with exec.
  • TM-DOS-063 tests were updated: bash ignores a pre-set v=-1 and allocates fd 10, so the old tests expecting "invalid file descriptor" were replaced. The fd cap (max_file_descriptors) still applies and has a new test.
  • Remaining gaps are pre-existing and recorded in limitations.md (no shared position for N<>file, 3<file also feeds stdin, output to fds 3-9 from a command's own redirect is dropped).

Checklist

  • Tests added or updated
  • Backward compatibility considered

Generated by Claude Code

@chaliy chaliy self-assigned this Oct 8, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 6adc852 Commit Preview URL

Branch Preview URL
Oct 08 2026, 01:45 AM

@chaliy
chaliy merged commit a8df016 into main Oct 8, 2026
49 checks passed
@chaliy
chaliy deleted the claude/project-thread-eafupr-bb-namedfd branch October 8, 2026 02:10
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.

1 participant