@jarkko this is demonstrating the second part of the function's effect, "[...] and prevents inheriting any parent process environment variables"
`env_clear()` serves an important purpose even on a fresh Command instance. By default, a new Command inherits ALL environment variables from the parent process. `env_clear()` explicitly clears this inherited environment, giving you a clean slate.
So these two are different:
Command::new("ls") // Inherits env vars from parent
Command::new("ls").env_clear() // Starts with empty env
And perhaps a little explanation as to why they chose `ls` in this example:
this command can actually be affected by environment variables!
For example, LS_COLORS controls the colors of files/directories.
So env_clear() would make `ls` run with none of these customizations, giving you predictable "vanilla" behavior regardless of what env vars the parent process had set.
@jarkko Yeah, the examples could have been better: https://github.com/rust-lang/rust/pull/135176/files