Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fc75f72

Browse files
committed
also use 'env' for printing unsetting
1 parent 53a29e0 commit fc75f72

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

library/std/src/process/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ fn debug_print() {
544544

545545
let mut command_with_removed_env = Command::new("boring-name");
546546
command_with_removed_env.env_remove("FOO").env_remove("BAR");
547-
assert_eq!(format!("{command_with_removed_env:?}"), r#"unset BAR FOO && "boring-name""#);
547+
assert_eq!(format!("{command_with_removed_env:?}"), r#"env -u BAR -u FOO "boring-name""#);
548548
assert_eq!(
549549
format!("{command_with_removed_env:#?}"),
550550
format!(

library/std/src/sys/unix/process/process_common.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,21 +562,17 @@ impl fmt::Debug for Command {
562562
write!(f, "env -i ")?;
563563
// Altered env vars will be printed next, that should exactly work as expected.
564564
} else {
565-
// Removed env vars need a separate command.
566-
// We use a single `unset` command for all of them.
565+
// Removed env vars need the command to be wrappen in `env`.
567566
let mut any_removed = false;
568567
for (key, value_opt) in self.get_envs() {
569568
if value_opt.is_none() {
570569
if !any_removed {
571-
write!(f, "unset ")?;
570+
write!(f, "env ")?;
572571
any_removed = true;
573572
}
574-
write!(f, "{} ", key.to_string_lossy())?;
573+
write!(f, "-u {} ", key.to_string_lossy())?;
575574
}
576575
}
577-
if any_removed {
578-
write!(f, "&& ")?;
579-
}
580576
}
581577
// Altered env vars can just be added in front of the program.
582578
for (key, value_opt) in self.get_envs() {

0 commit comments

Comments
 (0)