diff options
| author | Ralf Jung <post@ralfj.de> | 2023-08-03 12:14:58 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-08-24 08:10:09 +0200 |
| commit | fc75f723f681dc2cb1b0be7395c936adfb2f6f63 (patch) | |
| tree | 282ecb85f536936040f5dc40d91a1120a405b9f5 | |
| parent | 53a29e0e60b14486fbe06d0d68f311989d693816 (diff) | |
| download | rust-fc75f723f681dc2cb1b0be7395c936adfb2f6f63.tar.gz rust-fc75f723f681dc2cb1b0be7395c936adfb2f6f63.zip | |
also use 'env' for printing unsetting
| -rw-r--r-- | library/std/src/process/tests.rs | 2 | ||||
| -rw-r--r-- | library/std/src/sys/unix/process/process_common.rs | 10 |
2 files changed, 4 insertions, 8 deletions
diff --git a/library/std/src/process/tests.rs b/library/std/src/process/tests.rs index b50dea2e737..72894142d17 100644 --- a/library/std/src/process/tests.rs +++ b/library/std/src/process/tests.rs @@ -544,7 +544,7 @@ fn debug_print() { let mut command_with_removed_env = Command::new("boring-name"); command_with_removed_env.env_remove("FOO").env_remove("BAR"); - assert_eq!(format!("{command_with_removed_env:?}"), r#"unset BAR FOO && "boring-name""#); + assert_eq!(format!("{command_with_removed_env:?}"), r#"env -u BAR -u FOO "boring-name""#); assert_eq!( format!("{command_with_removed_env:#?}"), format!( diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs index 23d9f3b78ee..957947a674a 100644 --- a/library/std/src/sys/unix/process/process_common.rs +++ b/library/std/src/sys/unix/process/process_common.rs @@ -562,21 +562,17 @@ impl fmt::Debug for Command { write!(f, "env -i ")?; // Altered env vars will be printed next, that should exactly work as expected. } else { - // Removed env vars need a separate command. - // We use a single `unset` command for all of them. + // Removed env vars need the command to be wrappen in `env`. let mut any_removed = false; for (key, value_opt) in self.get_envs() { if value_opt.is_none() { if !any_removed { - write!(f, "unset ")?; + write!(f, "env ")?; any_removed = true; } - write!(f, "{} ", key.to_string_lossy())?; + write!(f, "-u {} ", key.to_string_lossy())?; } } - if any_removed { - write!(f, "&& ")?; - } } // Altered env vars can just be added in front of the program. for (key, value_opt) in self.get_envs() { |
