Repository navigation
fix: return real statuses from compounds in command substitution - #179
Open
ferdingler wants to merge 1 commit into
Open
ferdingler wants to merge 1 commit into
ferdingler wants to merge 1 commit into
Conversation
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.
This branch has not been deployed
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.
Description
Inside
$(...), a brace group, subshell,if, loop, orcasealways came back as success, whatever its last command did. SoX=$( { false; } && echo yes)set X toyes, where bash leaves it empty, and the||side never ran.$?read 0 right after one of these too, and even after a plainfalse.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.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.