A command-line argument is input supplied when a program starts. Unlike keyboard input read while the program is running, it is already available at launch. In Rust, `std::env::args()` provides these inputs as strings. section 18.2 section 18.2.2
The first entry is always the program name, even when the user supplies nothing else. Because `Args` can be iterated over, a loop can print each entry. Use `.skip(1)` when you want only the words the user added. section 18.2.2
use std::env::args;
fn main() {
let input = args();
input.skip(1).for_each(|item| {
println!(
"You wrote {item}, which in capital letters is {}",
item.to_uppercase()
);
})
}
This example skips the program name, then prints each remaining argument alongside an uppercase version. section 18.2.2
Use an argument as an instruction
A program can check the first user-supplied word for `capital` or `lowercase`, then print the following words in that form. For example, `cargo run capital I think I understand now` produces uppercase words. If the instruction is unrecognized, the example leaves the following words unchanged. section 18.2.2
Arguments are values passed on the command line; environment variables instead concern overall configuration. A familiar command-line argument is `--open` in `cargo doc --open`. section 18.5













