You can consider “” as glue, so everything inside the quotes will be treated as a single atomic component.
If they are part of Raw string literals, there will be no string interpolation, the same as in idiomatic rust. However, you can always use format! macro to form the new string. For example:
Notice here $awk_opts will be treated as single option passing to awk command.
If you want to use dynamic parameters, you can use $[] to access vector variable:
let gopts = vec![vec!["-l", "-a", "/"], vec!["-a", "/var"]];
for opts in gopts {
run_cmd!(ls $[opts])?;
}
I believe the idea is that the cmd_lib crate just makes it easy to construct a std::process::Command and arguments to it, but it deliberately won't inspect arguments and modify the way commands are executed and connected at runtime. Security is probably not a priority for the library, but doing things this way also automatically "escapes" arguments so you don't open yourself up to shell injection attacks.
If you just want to let the user run arbitrary commands, your best option is to explicitly spawn a shell which executes an arbitrary command (i.e. spawn!(bash -c $args)).
bummer. bash -c is not an option for me as i need a solution that is cross-platform. mac, linux, and windows. and do not want to use WSL.
i already have a bash script that does what i need, and am trying to port to a language which will natively work on windows too. was hoping rust could do that.