Skip to content

fix(expansion): pattern, case and transform operators on array elements - #2576

Merged
chaliy merged 1 commit into
mainfrom
claude/param-transforms
Oct 7, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/param-transforms

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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

What changed

Pattern, case and transform operators now work on array elements, whole arrays and $@/$*: ${a[@]/x/y}, ${a[i]#p}, ${a[@]%s}, ${a[@]^^}, ${m[k],}, ${a[@]@Q}, ${a[0]@U}. Quoted "${a[@]op}" and "${@op}" give one field per element. ${v^^pat}, ${v^pat}, ${v,,pat} and ${v,pat} change only the characters that match pat.

Why

These gaps were found by the pseudo-linus thread's Debian comparison (shell/param-case-modification, shell/param-transform-ops). Common agent idioms such as "${files[@]##*/}" or "${args[@]@Q}" silently produced wrong output.

Before

$ a=(xa ya); echo "${a[@]/a/b}" "${a[@]^^}" "${a[@]@Q}"
xa ya/a/b} xa ya^^} xa ya@Q}
$ v="hello world"; echo "${v^^[lo]}"
HELLO WORLD[lo]}
$ set -- ab 'c d'; printf '<%s>' "${@@Q}"
<'ab c d'>

After

$ a=(xa ya); echo "${a[@]/a/b}" "${a[@]^^}" "${a[@]@Q}"
xb yb XA YA 'xa' 'ya'
$ v="hello world"; echo "${v^^[lo]}"
heLLO wOrLd
$ set -- ab 'c d'; printf '<%s>' "${@@Q}"
<'ab'><'c d'>

All match bash 5.2. The new spec file param-array-ops.test.sh has 8 cases, each checked against real bash.

Risk

Low. The interpreter already applied these operators per element; only the parser was missing the operator after ]. Per-element output keeps the existing 10 MB expansion cap. ${v~}/${v~~} (undocumented case toggles) are still unsupported.

Checklist

  • Failing spec written first, verified against bash
  • cargo test -p bashkit --lib, --test integration, bash comparison
  • cargo clippy -D warnings, cargo fmt
  • Docs (compatibility.md) and knowledge/log.md updated

https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA


Generated by Claude Code

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

cloudflare-workers-and-pages Bot commented Oct 7, 2026 •

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 b08725b Commit Preview URL

Branch Preview URL
Oct 07 2026, 05:26 PM

`${a[@]/x/y}`, `${a[i]#p}`, `${a[@]^^}`, `${a[@]@q}` and friends printed
the array followed by the operator text. The parser now parses these
operators after a subscript, quoted `"${a[@]op}"` / `"${@op}"` keep one
field per element, and `${v^^pat}`-style case changes honour the pattern.

Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
@chaliy
chaliy force-pushed the claude/param-transforms branch from 903e3e2 to b08725b Compare October 7, 2026 17:26
@chaliy
chaliy merged commit 0031fe6 into main Oct 7, 2026
47 checks passed
@chaliy
chaliy deleted the claude/param-transforms branch October 7, 2026 17:48
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