Skip to content
Merged
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
25 changes: 19 additions & 6 deletions crates/util/src/shell_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,17 @@ impl ShellBuilder {
});
if self.redirect_stdin {
match self.kind {
ShellKind::Fish | ShellKind::Posix => {
combined_command.insert_str(0, "exec </dev/null; ");
ShellKind::Posix => {
// Perform the STDIN redirection prior to the actual
// command on a separate line, so that it is already
// active if the command contains a syntax error.
// Otherwise, with -i, dash will fall back to an
// interactive shell in this case.
combined_command.insert_str(0, "exec </dev/null\n");
}
ShellKind::Fish => {
combined_command.insert_str(0, "begin; ");
combined_command.push_str("; end </dev/null");
}
ShellKind::Nushell
| ShellKind::Csh
Expand Down Expand Up @@ -143,8 +152,12 @@ impl ShellBuilder {
});
if self.redirect_stdin {
match self.kind {
ShellKind::Fish | ShellKind::Posix => {
combined_command.insert_str(0, "exec </dev/null; ");
ShellKind::Posix => {
combined_command.insert_str(0, "exec </dev/null\n");
}
ShellKind::Fish => {
combined_command.insert_str(0, "begin; ");
combined_command.push_str("; end </dev/null");
}
ShellKind::Nushell
| ShellKind::Csh
Expand Down Expand Up @@ -282,7 +295,7 @@ mod test {
.build(Some("echo".into()), &["test".to_string()]);

assert_eq!(program, "fish");
assert_eq!(args, vec!["-i", "-c", "exec </dev/null; echo test"]);
assert_eq!(args, vec!["-i", "-c", "begin; echo test; end </dev/null"]);
}

#[test]
Expand All @@ -298,7 +311,7 @@ mod test {
assert_eq!(program, "sh");
assert_eq!(
args,
vec!["-i", "-c", "exec </dev/null; cat <<EOF\nhello\nEOF"]
vec!["-i", "-c", "exec </dev/null\ncat <<EOF\nhello\nEOF"]
);
}

Expand Down
Loading