Repository navigation
fix(builtins): return, unset -v and read reject bad arguments - #2613
Merged
Merged
Conversation
`return` at the top level ended the script with status 0 instead of reporting a usage error, so a stray `return` silently truncated a run. `return N` inside a sourced script lost its status. `unset -v` accepted names it could never have assigned, and `read -t`/`-n` ignored a non-numeric argument instead of failing. Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 956b99b | Commit Preview URL Branch Preview URL |
Oct 07 2026, 11:53 PM |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Михайло · project thread
What changed
Four builtin argument checks bash makes and bashkit did not:
returnoutside a function or a sourced script reports and exits 2, and the script carries onreturn Ninside a sourced script issource's statusunset -vinsists the name is one it could have assigned; plainunsetandunset -fstill take any wordread -tandread -nreport a non-numeric argument instead of ignoring the optionWhy
The
returncase is the one that bites. A stray top-levelreturn— left overfrom editing, or in a file meant to be sourced and run directly instead — ended
the whole run with status 0. The script looked like it succeeded while most of
it never ran.
Before / After
bash: return: can only \return' from a function or sourced scripton stderr, thenrc=2,after`in,rc=4in,rc=0in,rc=4unset -v 'arr['unset: `arr[': not a valid identifier, 1unset 'arr['unset -v 'a[0]'read -t abc xread: abc: invalid timeout specification, 1read -n abc xread: abc: invalid number, 1Risk
Low.
returninside a function andread -n 3are covered by new tests andunchanged. The interpreter gained a
source_depthcounter soreturncan tella sourced script from a top-level one; a frame that only carries top-level
positional parameters (
bashkit script.sh a b) does not makereturnlegal,which is what bash does.
read -dwith no argument still exits 1 rather than bash's 2-with-usage; thatis a separate gap and not touched here.
Checklist
cargo test -p bashkit --lib(2916 passed)cargo test -p bashkit --test integration(1360 passed)bash_comparisondifferential tests against real bashcargo clippy -p bashkit --all-targets -- -D warningscargo fmt --all --checkcargo test -p bashkit-cli(56 passed)just check-okflog.md)https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
Generated by Claude Code