diff --git a/crates/util/src/shell_builder.rs b/crates/util/src/shell_builder.rs index 57ce0319a403f7..76ff3923e6250f 100644 --- a/crates/util/src/shell_builder.rs +++ b/crates/util/src/shell_builder.rs @@ -99,8 +99,17 @@ impl ShellBuilder { }); if self.redirect_stdin { match self.kind { - ShellKind::Fish | ShellKind::Posix => { - combined_command.insert_str(0, "exec { + // 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 { + combined_command.insert_str(0, "begin; "); + combined_command.push_str("; end { - combined_command.insert_str(0, "exec { + combined_command.insert_str(0, "exec { + combined_command.insert_str(0, "begin; "); + combined_command.push_str("; end