Skip to content

fix(parser): {arr[i]} is an fd variable in every redirect position - #2617

Merged
chaliy merged 1 commit into
mainfrom
claude/fdvar-close-array
Oct 8, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/fdvar-close-array

Conversation

@chaliy

@chaliy chaliy commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

What changed

{arr[i]} is recognised as a redirect's fd variable wherever one may appear,
not only in the close form: exec {A[1]}> file and exec {A[1]}>&- both work,
and a subscript may be a variable ({A[i]}).

Why

Follow-up to #2605. That PR allowed brackets in the name but the check still
required the word to be a single literal part, and {A[1]} lexes as several —
[ opens a glob bracket. So the redirect parsed as a command:

$ exec {A[1]}> o.txt
bash: {A[1]}: command not found    # and status 127

Before / After

declare -a A
A[1]=7
exec {A[1]}> o.txt
echo hi >&"${A[1]}"
exec {A[1]}>&-
cat o.txt
output status
bash 5.2 hi 0
bashkit before bash: {A[1]}: command not found 127
bashkit after hi 0

A brace word that is not an fd variable is still a command: {A-1}> o.txt
reports command not found in both shells.

Risk

Low and parser-local. The name is now read from the word's literal parts
joined; a word with any non-literal part (an expansion, a substitution) yields
nothing and is left alone, so ${x}> file and $(cmd)> file parse as before.

Checklist

  • cargo test -p bashkit --lib (2920 passed)
  • cargo test -p bashkit --test integration (1372 passed)
  • New spec case and 4 integration tests, verified against bash 5.2
  • bash_comparison differential tests against real bash
  • cargo clippy -p bashkit --all-targets -- -D warnings
  • cargo fmt --all --check
  • cargo test -p bashkit-cli (56 passed)
  • just check-okf
  • Stack probe: 1900 KB, inside the two-MiB TM-DOS-020 budget
  • Knowledge updated (log.md)

https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA


Generated by Claude Code

`exec {A[1]}> file` parsed as a command named `{A[1]}` and failed with
`command not found`. The name lexes as several literal parts, because `[`
opens a glob bracket, and the fd-variable check only looked at a word
made of one part. Follow-up to #2605, which covered the close form.

Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
@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 5204c04 Commit Preview URL

Branch Preview URL
Oct 08 2026, 12:35 AM

@chaliy
chaliy merged commit 43c735c into main Oct 8, 2026
44 checks passed
@chaliy
chaliy deleted the claude/fdvar-close-array branch October 8, 2026 01:18
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