diff --git a/crates/nu-command/src/filesystem/ucp.rs b/crates/nu-command/src/filesystem/ucp.rs index 82ab62dfa2..3c3d810469 100644 --- a/crates/nu-command/src/filesystem/ucp.rs +++ b/crates/nu-command/src/filesystem/ucp.rs @@ -209,6 +209,8 @@ impl Command for UCp { } } + let target_path = nu_path::expand_path_with(&target_path, &cwd); + let options = uu_cp::Options { overwrite, reflink_mode, diff --git a/crates/nu-command/tests/commands/ucp.rs b/crates/nu-command/tests/commands/ucp.rs index abcf9fd64c..e0f7faca8f 100644 --- a/crates/nu-command/tests/commands/ucp.rs +++ b/crates/nu-command/tests/commands/ucp.rs @@ -970,6 +970,21 @@ fn test_cp_with_vars() { }); } +#[test] +fn test_cp_destination_after_cd() { + Playground::setup("ucp_test_34", |dirs, sandbox| { + sandbox.mkdir("test"); + sandbox.with_files(vec![EmptyFile("test/file.txt")]); + nu!( + cwd: dirs.test(), + // Defining variable avoid path expansion of cp argument. + // If argument was not expanded ucp wrapper should do it + "cd test; let file = 'copy.txt'; cp file.txt $file", + ); + assert!(dirs.test().join("test").join("copy.txt").exists()); + }); +} + #[rstest] #[case(r#"'a]c'"#)] #[case(r#"'a[c'"#)]