Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,13 +1438,17 @@ impl Interpreter {
self.coproc_buffers = saved_coproc;
self.memory_budget = saved_memory_budget;

// Consume Exit control flow at subshell boundary — exit only
// terminates the subshell, not the parent shell.
if let Ok(ref mut res) = result
&& let ControlFlow::Exit(code) = res.control_flow
{
res.exit_code = code;
res.control_flow = ControlFlow::None;
// Consume Exit and Return control flow at subshell boundary —
// they only terminate the subshell, not the parent shell.
// Return is used by ${var:?msg} error handling and nounset errors.
if let Ok(ref mut res) = result {
match res.control_flow {
ControlFlow::Exit(code) | ControlFlow::Return(code) => {
res.exit_code = code;
res.control_flow = ControlFlow::None;
}
_ => {}
}
}

result
Expand Down
8 changes: 8 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/subshell.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,11 @@ echo "$@"
x y
a b c
### end

### parameter_error_in_subshell_contained
# ${var:?msg} error in subshell should not kill parent
(unset NOSUCHVAR; echo "${NOSUCHVAR:?gone}" 2>/dev/null)
echo "survived: $?"
### expect
survived: 1
### end
Loading