@@ -26,8 +26,10 @@ pub struct Prepare {
26
26
pub args : Vec < OsString > ,
27
27
/// environment variables to set in the spawned process.
28
28
pub env : Vec < ( OsString , OsString ) > ,
29
- /// If `true`, we will use `sh` to execute the `command`.
29
+ /// If `true`, we will use `shell_program` or ` sh` to execute the `command`.
30
30
pub use_shell : bool ,
31
+ /// The name or path to the shell program to use instead of `sh`.
32
+ pub shell_program : Option < OsString > ,
31
33
/// If `true` (default `true` on windows and `false` everywhere else)
32
34
/// we will see if it's safe to manually invoke `command` after splitting
33
35
/// its arguments as a shell would do.
@@ -103,6 +105,12 @@ mod prepare {
103
105
self
104
106
}
105
107
108
+ /// Set the name or path to the shell `program` to use, to avoid using the default shell which is `sh`.
109
+ pub fn with_shell_program ( mut self , program : impl Into < OsString > ) -> Self {
110
+ self . shell_program = Some ( program. into ( ) ) ;
111
+ self
112
+ }
113
+
106
114
/// Unconditionally turn off using the shell when spawning the command.
107
115
/// Note that not using the shell is the default so an effective use of this method
108
116
/// is some time after [`with_shell()`][Prepare::with_shell()] was called.
@@ -199,7 +207,10 @@ mod prepare {
199
207
cmd
200
208
}
201
209
None => {
202
- let mut cmd = Command :: new ( if cfg ! ( windows) { "sh" } else { "/bin/sh" } ) ;
210
+ let mut cmd = Command :: new (
211
+ prep. shell_program
212
+ . unwrap_or ( if cfg ! ( windows) { "sh" } else { "/bin/sh" } . into ( ) ) ,
213
+ ) ;
203
214
cmd. arg ( "-c" ) ;
204
215
if !prep. args . is_empty ( ) {
205
216
if prep. command . to_str ( ) . map_or ( true , |cmd| !cmd. contains ( "$@" ) ) {
@@ -417,6 +428,7 @@ pub mod shebang {
417
428
pub fn prepare ( cmd : impl Into < OsString > ) -> Prepare {
418
429
Prepare {
419
430
command : cmd. into ( ) ,
431
+ shell_program : None ,
420
432
context : None ,
421
433
stdin : std:: process:: Stdio :: null ( ) ,
422
434
stdout : std:: process:: Stdio :: piped ( ) ,
0 commit comments