diff --git a/crates/nu-command/src/filesystem/ucp.rs b/crates/nu-command/src/filesystem/ucp.rs index 82ab62dfa..3c3d81046 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 abcf9fd64..e0f7faca8 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'"#)]