diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 6a3f6f21b11..997c11dce30 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -191,7 +191,12 @@ impl Options { (tmpdir, template.to_string()) } Some(template) => { - let tmpdir = matches.get_one::(OPT_TMPDIR).map(String::from); + let tmpdir = if matches.get_flag(OPT_T) { + // mktemp -t foo.xxx should export in TMPDIR + Some(env::temp_dir().display().to_string()) + } else { + matches.get_one::(OPT_TMPDIR).map(String::from) + }; (tmpdir, template.to_string()) } } diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index 907f8cf1dea..fecbe98ceed 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -857,3 +857,18 @@ fn test_default_missing_value() { let scene = TestScenario::new(util_name!()); scene.ucmd().arg("-d").arg("--tmpdir").succeeds(); } + +#[test] +fn test_default_issue_4821_t_tmpdir() { + let scene = TestScenario::new(util_name!()); + let pathname = scene.fixtures.as_string(); + let result = scene + .ucmd() + .env(TMPDIR, &pathname) + .arg("-t") + .arg("foo.XXXX") + .succeeds(); + let stdout = result.stdout_str(); + println!("stdout = {stdout}"); + assert!(stdout.contains(&pathname)); +}