Skip to content

fix: return real statuses from compounds in command substitution - #179

Open
ferdingler wants to merge 1 commit into
strands-agents:mainfrom
ferdingler:fix/captured-compound-status
Open

ferdingler wants to merge 1 commit into
strands-agents:mainfrom
ferdingler:fix/captured-compound-status

Conversation

@ferdingler

Copy link
Copy Markdown
Collaborator

Description

Inside $(...), a brace group, subshell, if, loop, or case always came back as success, whatever its last command did. So X=$( { false; } && echo yes) set X to yes, where bash leaves it empty, and the || side never ran. $? read 0 right after one of these too, and even after a plain false.

Now each of those carries the real status of the last command it ran, and $? inside the substitution follows along. This only touches the command substitution path.

I checked every new expectation against bash 5.2 first. Without the fix, 22 of the new tests failed; with it, they all pass, along with the success cases and the rest of the suite. There's some overlap in the same file with #169, #173, #174 and #176, but not on the same lines. A few related problems are still open and I left them for separate changes: the status of the substitution itself (X=$(exit 3); echo $? prints 0), a group with an input redirect inside $(...) still reports success, and ! in front of a group or other compound gets dropped. Inside $(...), that last one now behaves the same as it does outside, so ! { false; } is wrong in both places. Before, it happened to be right inside a substitution.

Related Issues

None.

Documentation PR

None.

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

A brace group, subshell, if, loop, or case run inside $(...) always
reported success, so a following && or || took the wrong branch and $?
read 0. Carry the status of the last command each compound ran, and set
$? after each item in the captured command line.
@ferdingler
ferdingler requested a review from a team as a code owner October 21, 2026 05:19

This branch has not been deployed

No deployments
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