nushell
nushell copied to clipboard
cp command gives an error when running from a script file but not from command line
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
I'm wondering if it makes any difference if you change this
cp -r day00 $new_dir
to this
cp -r day00 ($new_dir)
Well I just tried that right now and it doesn't haha the error is the same.
Bizarrely, this still produces an error, even with the uutils cp
:
/tmp/mine> nu script.nu 02
Error: × is not a directory
╭─[/tmp/mine/script.nu:2:1]
2 │ let new_dir = $"day($day_number)/"
3 │ cp -r day00 $new_dir
· ────┬───
· ╰── is not a directory
4 │ }
╰────
Whereas both cp -r day00 day02
and cp -r day00 $new_dir
work.
I bet it's related to https://github.com/nushell/nushell/pull/10843 and https://github.com/nushell/nushell/issues/10832