Repository navigation
fix: join && and || line ends in sourced files - #248
Merged
Merged
Conversation
…arse errors A sourced file (`. file`, `source file`, `sh file`) ran each line that ended in `&&` or `||` as a complete statement. So `false &&` followed by `echo x` on the next line ran `echo x`. Bash joins the next line, so the guarded command does not run. The loop now reads more lines while the parsed statement ends in `&&` or `||`. A parse error in a sourced file did not name the file, and an unterminated statement at end of file gave no line. The error now shows `<file>: line <n>:`, as bash does. A `(` that cannot open anything is now a definite error, so the file stops at it and does not consume the rest of the file.
priyasingh2111
approved these changes
Nov 12, 2026
Contributor
|
Non-blocking: looks good. Two older gaps in the same area, if you want them here or in a follow-up:
Both behave the same on main, so neither is a regression. |
Collaborator
Author
|
Thanks for checking these! I reproduced both, and you're right that main does the same thing. I'm going to keep this PR to the two fixes it has, so I'm leaving these for a follow-up. |
10 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.
Description
In a sourced file (
. file,source file, orsh file), a line ending in&&or||was treated as a finished command. Sofalse &&withecho hion the next line still printedhi, and the same withtrue ||. Bash and zsh join the next line, so the guarded command doesn't run. A script that relies oncheck &&to gate the next line would run that line anyway.Parse errors in sourced files also didn't say which file they came from, and an unclosed statement at the end of a file gave no line at all. Now the shell joins the next line after a trailing
&&or||, and a parse error names the file and the line, the way bash does. A stray(that can't open anything now stops the file right there, instead of reading on to the end and reporting some unrelated error from further down. Earlier PRs fixed other parts of sourced-file parse errors; this covers what they left.I added tests for
.,source, andshthat check the guarded command doesn't run, the exit status, the file and line in the error, and that a parse error stops the file while the calling script keeps going. I also added a differential case recorded from real bash. Every new test fails on main and passes with the change. I compared the output with bash 5.2 by hand: same output, same file and line, same lines skipped. One difference stays: bash exits 2 on a syntax error, and Shell keeps exiting 1 as before. The full Rust suite, fmt, clippy, and docs pass, with no new warnings. I didn't run the Python or Node suites because the bindings aren't touched.Related Issues
#212 (
sh -c) also touches the code that runs a script file, so whichever lands second may need a small rebase.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.