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
9 changes: 9 additions & 0 deletions crates/bashkit/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2680,8 +2680,17 @@ impl Interpreter {
self.insert_variable_checked("OPTIND".to_string(), "1".to_string());
self.variables.remove("_OPTCHAR_IDX");

// Forward piped stdin to child when executing a script file or -c command
let saved_stdin = self.pipeline_stdin.take();
if script_file.is_some() || is_command_mode {
self.pipeline_stdin = stdin.clone();
}

let result = self.execute(&script).await;

// Restore stdin
self.pipeline_stdin = saved_stdin;

// Restore state
if let Some(val) = saved_optind {
self.insert_variable_checked("OPTIND".to_string(), val);
Expand Down
22 changes: 22 additions & 0 deletions crates/bashkit/tests/spec_cases/bash/bash-stdin-pipe.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### bash_builtin_stdin_pipe_to_script
# echo | bash script.sh should forward stdin
echo 'echo "got: $(cat)"' > /tmp/stdin_test.sh
echo "hello" | bash /tmp/stdin_test.sh
### expect
got: hello
### end

### bash_builtin_stdin_pipe_to_c
# echo | bash -c 'cat' should forward stdin
echo "piped" | bash -c 'cat'
### expect
piped
### end

### bash_builtin_stdin_read
# echo | bash script.sh with read builtin
echo 'read -r line; echo "line: $line"' > /tmp/read_test.sh
echo "test input" | bash /tmp/read_test.sh
### expect
line: test input
### end
Loading