diff --git a/src/uu/mktemp/src/mktemp.rs b/src/uu/mktemp/src/mktemp.rs index 997c11dce..20498337a 100644 --- a/src/uu/mktemp/src/mktemp.rs +++ b/src/uu/mktemp/src/mktemp.rs @@ -191,7 +191,9 @@ impl Options { (tmpdir, template.to_string()) } Some(template) => { - let tmpdir = if matches.get_flag(OPT_T) { + let tmpdir = if matches.contains_id(OPT_TMPDIR) { + matches.get_one::(OPT_TMPDIR).map(String::from) + } else if matches.get_flag(OPT_T) { // mktemp -t foo.xxx should export in TMPDIR Some(env::temp_dir().display().to_string()) } else { diff --git a/tests/by-util/test_mktemp.rs b/tests/by-util/test_mktemp.rs index fecbe98ce..788f1f14a 100644 --- a/tests/by-util/test_mktemp.rs +++ b/tests/by-util/test_mktemp.rs @@ -872,3 +872,19 @@ fn test_default_issue_4821_t_tmpdir() { println!("stdout = {stdout}"); assert!(stdout.contains(&pathname)); } + +#[test] +fn test_default_issue_4821_t_tmpdir_p() { + let scene = TestScenario::new(util_name!()); + let pathname = scene.fixtures.as_string(); + let result = scene + .ucmd() + .arg("-t") + .arg("-p") + .arg(&pathname) + .arg("foo.XXXX") + .succeeds(); + let stdout = result.stdout_str(); + println!("stdout = {stdout}"); + assert!(stdout.contains(&pathname)); +}