Skip to content

fix(interpreter): special params $0, $-, BASH_SUBSHELL, positional slices - #2586

Merged
chaliy merged 1 commit into
mainfrom
claude/special-vars
Oct 7, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/special-vars

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

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

What changed

Special parameters now behave like bash:

  • $0 keeps the script name inside functions and sourced files.
  • $- lists the active short options (h and B always on).
  • $BASH_SUBSHELL tracks the depth of ( ), $( ) and compound pipeline stages.
  • ${@:off[:len]} / ${*:off} slice positional parameters, with $0 at offset 0.
  • ${#} and ${-…}, ${?…}, ${$…} with operators now parse.
  • read -a keeps empty fields between delimiters.

Why

These are level-up roadmap step 1 fidelity gaps from the Debian-oracle shell cases. Scripts use $0 for usage messages, case $- in *i*) for interactivity checks, and "${@:2}" for argument forwarding.

Before / After

Script Before After (= bash)
f(){ echo $0; }; f f script name
echo "${-//c/}" `` hB
echo $BASH_SUBSHELL $(echo $BASH_SUBSHELL) $( (echo $BASH_SUBSHELL) ) 0 1 2
set -- a b c d; echo ${@:1} b c a b c d
set -- a b c d; echo ${#} 0 4
IFS=, read -ra p <<< a,b,,d; echo ${#p[@]} 3 4

Proof: new spec special-vars-subshell.test.sh (bash-verified), bash_comparison passes.

Risk

Low. $- now reports hB, and one security test was updated for that. BASH_SUBSHELL is a counter that is saved and restored with the subshell snapshot.

Checklist

  • Failing spec first, then fix
  • cargo test -p bashkit --lib / --test integration / bash_comparison
  • clippy -D warnings, fmt
  • knowledge/log.md updated

https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA


Generated by Claude Code

…ices

- $0 keeps script name inside functions and sourced files
- $- reports active short options (h and B always on)
- BASH_SUBSHELL tracks subshell / cmd-subst / pipeline-stage depth
- ${@:off[:len]} and ${*:off} slice positional params
- ${#}, ${-...}, ${?...}, ${$...} parse as special params
- read -a keeps empty fields between delimiters

Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
@chaliy chaliy self-assigned this Oct 7, 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 25b5e67 Commit Preview URL

Branch Preview URL
Oct 07 2026, 06:44 PM

@chaliy
chaliy merged commit e1e0b35 into main Oct 7, 2026
44 checks passed
@chaliy
chaliy deleted the claude/special-vars branch October 7, 2026 19:11
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