I am trying to execute a shell command from Deno where one of the args contains an asterisk. Example:
const output = new Deno.Command("cp", { args: ["source/*", "destination"] }).outputSync()
console.error(new TextDecoder().decode(output.stderr))
It yields:
cp: cannot stat 'source/*': No such file or directory
How can I pass an asterisk to one of the Deno.Command
args?
Deno uses Rust's std:process::Command
Note that the argument is not passed through a shell, but given literally to the program. This means that shell syntax like quotes, escaped characters, word splitting, glob patterns, substitution, etc. have no effect.
So in order to use *
you'll need to spawn a shell (sh
, bash
) as Glenn Jackman commented.
new Deno.Command("sh", { args: ["-c", "cp source/* destination"] }).outputSync()