about summary refs log tree commit diff
path: root/library/std/src/sys/unix
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/unix')
-rw-r--r--library/std/src/sys/unix/process/process_common.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs
index 9362fc7f205..3a02a6c20d9 100644
--- a/library/std/src/sys/unix/process/process_common.rs
+++ b/library/std/src/sys/unix/process/process_common.rs
@@ -558,11 +558,25 @@ impl fmt::Debug for Command {
             if let Some(ref cwd) = self.cwd {
                 write!(f, "cd {cwd:?} && ")?;
             }
+            // Removed env vars need a separate command.
+            // We use a single `unset` command for all of them.
+            let mut any_removed = false;
+            for (key, value_opt) in self.get_envs() {
+                if value_opt.is_none() {
+                    if !any_removed {
+                        write!(f, "unset ")?;
+                        any_removed = true;
+                    }
+                    write!(f, "{} ", 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() {
                 if let Some(value) = value_opt {
                     write!(f, "{}={value:?} ", key.to_string_lossy())?;
-                } else {
-                    write!(f, "unset({}) ", key.to_string_lossy())?;
                 }
             }
             if self.program != self.args[0] {