Repository navigation
fix: pass piped and redirected stdin to sh scripts - #224
Merged
ferdingler merged 3 commits intoNov 12, 2026
Merged
Conversation
ferdingler
marked this pull request as ready for review
November 9, 2026 23:51
Collaborator
Author
|
@strandly-the-agent please review |
3 tasks done
strandly-the-agent
approved these changes
Nov 12, 2026
strandly-the-agent
left a comment
Collaborator
There was a problem hiding this comment.
Approve. The 3-line move at src/exec.rs:3553 does what the PR says, and I found no regressions. Piped, redirected, heredoc, and shebang stdin now reach the script. Each case I ran matches bash, and none of them worked on main before.
@ferdingler, one question, not blocking: the body says this depends on #199, but #199 is already on main (merged 11-06), and script stdout through pipes and $(...) works on this branch. You could probably drop that note.
✅ What I verified
- Head
1775f8f.cargo test --workspace --all-targets: 2156 passed, 0 failed.script_*: 24 passed. The 3 new tests fail onmain. - I ran about 75 probes against this branch,
main@a064834, and real bash (my runs plus an independent reviewer pass). These now match bash: successivereads,read; cat,while read, a function inside the script, the script in the middle of a pipeline,< file, heredoc,</dev/null,& wait, and$(echo x | sh r.sh). - No leaks or hangs.
echo x | sh r.sh; read zdoesn't reach the parent. A script that doesn't read, or reads one line of about 1.4 MB, still exits.
Appendix: non-blocking (3)
- ⚪ No test checks that stdin survives across commands inside one script.
printf 'a\nb\n' | sh r2.shwithread a; read bwould cover it. (Probing shows it works.) - ⚪
exec < fileinside a piped script now reads the pipe instead of the file. Bash readsL1, this branch readshi, andmainerrored. Functions already do the same onmain, andexec <doesn't persist even at top level, so this isn't caused by this PR. - Not caused by this PR, filed as #249: a command in a
while read … done < listbody (ls,x | cat,sh s.sh) takes the loop's stdin throughexec.rs:3483, so the loop runs only once. Bothmainand this branch prints:athenread: bad fd 0; bash printss:a s:b s:c. The same root cause makes a nestedsh inner.sh; catlose unread input. That's the compound-stdin follow-up you mentioned.
10 tasks done
10 tasks done
8 of 10 tasks
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
When you pipe or redirect into a script run with
sh(or through a shebang), the script never sees that input. Socatinside it prints nothing andreadfails:bash prints
got x. Now the script gets the stdin of its pipeline stage, the same way shell functions already do, so pipes,< fileand heredocs all reach it. The same command printsgot xwith this change. It should land together with or after #199. Without #199, a script's stdout still ignores pipes and$(...)in-c/REPL mode, so the visible fix there depends on it.I compared piped, redirected, heredoc and
/dev/nullinput with bash. I also checked a script that reads one line of many, one that doesn't read at all, and that the pipe doesn't leak back to the parent shell afterwards. The new tests fail on main and pass here, and the branch merges cleanly with #199 with the script tests passing on the combination. A script inside a loop or brace group that reads the compound's stdin still behaves differently from bash; that's a separate follow-up.Related Issues
Part of #207
Documentation PR
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.