diff --git a/src/uu/shred/src/shred.rs b/src/uu/shred/src/shred.rs index f35b1a0db2c..d998994f663 100644 --- a/src/uu/shred/src/shred.rs +++ b/src/uu/shred/src/shred.rs @@ -626,8 +626,16 @@ fn wipe_file( verbose: bool, force: bool, ) -> UResult<()> { - // Get these potential errors out of the way first + #[cfg(unix)] + let path = if path_str == "-" { + Path::new("/dev/fd/1") + } else { + Path::new(path_str) + }; + + #[cfg(not(unix))] let path = Path::new(path_str); + if !path.exists() { return Err(USimpleError::new( 1, diff --git a/tests/by-util/test_shred.rs b/tests/by-util/test_shred.rs index 81f69fb5c66..4928611bb19 100644 --- a/tests/by-util/test_shred.rs +++ b/tests/by-util/test_shred.rs @@ -420,3 +420,18 @@ fn test_gnu_shred_passes_different_counts() { result.stderr_contains("pass 1/19 (random)"); result.stderr_contains("pass 19/19 (random)"); } + +#[test] +#[cfg(unix)] +fn test_shred_dash_wipes_stdout_file() { + let (at, mut ucmd) = at_and_ucmd!(); + let file = "secret.txt"; + at.write(file, "secret data"); + + ucmd.arg("-n1") + .arg("-") + .set_stdout(at.make_file(file)) + .succeeds(); + + assert_ne!(at.read(file), "secret data"); +}