Repository navigation
fix(interpreter): ERR/RETURN trap scoping and N>&word redirects like bash - #2631
Merged
Merged
Conversation
ERR fires after the failing simple command, multi-command pipeline, ( ), [[ ]] or (( )) itself, only when a handler was set before the command ran. Functions inherit ERR only under set -E and RETURN only under set -T; subshells, command substitutions and pipeline stages keep ERR listed but dormant without set -E. RETURN now runs when a function or sourced file finishes, and trap handlers count $LINENO from the triggering line.
N>&- closes the descriptor for the command (stderr vanishes, stdout writes fail), >&file and 1>&file send both streams to the file like &>file, 2>&file is an ambiguous redirect, and 2>&$fd duplicates the expanded descriptor instead of writing a file named after it. A failed &>/>& open drops the command's output. for (( )) headers run their $(...) each time an expression is evaluated.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 924a4b0 | Commit Preview URL Branch Preview URL |
Oct 08 2026, 04:01 AM |
…-eafupr-bb-builtins # Conflicts: # crates/bashkit/src/interpreter/mod.rs # knowledge/operations/limitations.md
…-eafupr-bb-builtins # Conflicts: # crates/bashkit/src/interpreter/mod.rs
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
eval, multi-command pipelines,( ),[[ ]],(( ))); lists and compound commands no longer fire it a second time. Functions, subshells,$( )and pipeline stages don't inherit ERR unlessset -Eis on; a trap set inside a function stays set; a function that sets ERR doesn't fire it for its own call.$LINENOin the handler is the failing line.$?, and is inherited by functions only underset -T.N>&wordredirects.2>&-closes stderr for that command (it used to act like2>&1),>&file/1>&filemean&>file,2>&fileis an ambiguous redirect, and2>&$fdduplicates the fd instead of writing a file named after it. A failed&>open no longer prints the command's output.for ((...))re-runs$(...)in its init, condition and step.Why
BashBox corpus batch: all 17 skipped cases in
bashbox-interpreter-builtins.test.shand all 10 inbashbox-err-trap.test.shnow pass (10 of the 27 were already fixed by earlier batches and only lost their skip lines).Before / After
errin/[errsub]/ls: cannot access '/nope': .../z(stderr lost)in/[sub]/err/z/eset -T; trap 'echo r' RETURN; g(){ :; }; f(){ g; }; f; echo endprinted onlyend; it now printsr r end, like bash.Risk
execute_command; covered by 9 newtrap-scopecases plus the corpus, all recorded from bash 5.2. New handling sits in boxed helpers so the recursion stack budget (function_recursion_is_bounded_on_a_two_mib_stack) is unchanged.limitations.md): a write error after a command's own>&-doesn't name the command; the DEBUG trap still runs in subshells withoutset -T.Checklist
Generated by Claude Code