cp command gives an error when running from a script file but not from command line
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 85
Description
Describe the bug
I'm solving de Advent of Code 2022 and I have a short script that let's me initialize my template for solving the problems of a day. It goes like this:
def main [day_number: string] {
let new_dir = $"day($day_number)/"
cp -r day00 $new_dir
code $new_dir
}
The cp command returns an error but when I run the same lines, one by one on the terminal, it just works!
Here's the error:
Error: nu::shell::directory_not_found (link)
× Directory not found
╭─[initialize_day.nu:2:1]
2 │ let new_dir = $"day($day_number)/"
3 │ cp -r day00 $new_dir
· ────┬───
· ╰── directory not found
4 │ code $new_dir
╰────
help: destination directory does not exist
This script worked fine in the previous version of nu I had installed, unfortunetly I don't remember which one it was, if I managed to get the version from the cache of pacman I'll update the issue with the version I had previously.
According to the pacman cache, the version I was using before was 0.71.0.
How to reproduce
- Save the script above to a .nu file.
- Have a dir named day00 in the same directory where you'll run the script.
- Run the command using
nu {filename}.nu 02.
Expected behavior
I expected nu to work in the same way that it did when I inputted the same lines one by one.
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.72.0 |
| branch | makepkg |
| commit_hash | 8fa965118c2e5a0beaa528d07eaf9b33d96779cb |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.65.0 (Arch Linux rust 1:1.65.0-1) |
| cargo_version | cargo 1.65.0 |
| pkg_version | 0.72.0 |
| build_time | 2022-11-30 06:57:53 +00:00 |
| build_rust_channel | release |
| features | database, default, trash, which, zip |
| installed_plugins |
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the command from initialize_day.nu with Nushell 0.72.0, then compare it with running the same lines interactively using the provided day00 and day02 setup. Trace the cp invocation and its destination handling; done means the script and interactive command behave consistently, with a regression test covering the case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100