You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::process::Command;
...let s = Command::new("echo").arg("$123").output().expect("command failed");println!("{}",String::from_utf8_lossy(&s.stdout));
I expected to see this happen:
Print the content of the $123 environment variable
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.
I guess we can expand "substitution" into "variable substitution" to make it more clear.
Activity
crumblingstatue commentedon Mar 28, 2022
It is the shell that resolves environment variables. You're not using a shell here, just directly executing a command. This is behaving as expected.
jfrimmel commentedon Mar 28, 2022
Indeed, this is the expected behavior. This can be circumvented by actually using a shell, e.g. on POSIX:
wwylele commentedon Mar 28, 2022
I did a quick check on the doc for arg
I guess we can expand "substitution" into "variable substitution" to make it more clear.
Milo123459 commentedon Sep 25, 2023
so is this just a documentation change?
@rustbot claim
Rollup merge of rust-lang#116146 - Milo123459:milo/clarify-arg-docume…
Unrolled build for rust-lang#116146