Skip to content

Error on the commands 'cp', 'mv', 'rm', and 'open' on files that have [ ] on its path #9310

@ynhame

Description

@ynhame

Describe the bug

nushell is able to find the file test[].txt:

nu❯ ls
╭───┬────────────┬──────┬──────┬───────────────╮
│ # │    name    │ type │ size │   modified    │
├───┼────────────┼──────┼──────┼───────────────┤
│ 0 │ test.txt   │ file │ 13 B │ 9 minutes ago │
│ 1 │ test[].txt │ file │ 13 B │ 9 minutes ago │
╰───┴────────────┴──────┴──────┴───────────────╯

nu❯ ls | get name | path exists
╭───┬──────╮
│ 0 │ true │
│ 1 │ true │
╰───┴──────╯

but is not able to open it:

nu❯ open test[].txt
Error: 
  × Error extracting glob pattern
   ╭─[entry #21:1:1]
 1 │ open test[].txt
   · ──┬─
   ·   ╰── Pattern syntax error near position 40: invalid range pattern
   ╰────

if I try to open the file without [ ] it works just fine:

nu❯ open test.txt
 lorem ipsum

using any kind of quotes does not help (", ', `)

nu✗ open `test[].txt`
Error: 
  × Error extracting glob pattern
   ╭─[entry #27:1:1]
 1 │ open `test[].txt`
   · ──┬─
   ·   ╰── Pattern syntax error near position 40: invalid range pattern
   ╰────

the cp, and rm commands exhibits the same error

nu✗ rm 'test[].txt'
Error: 
  × Pattern syntax error near position 40: invalid range pattern
   ╭─[entry #31:1:1]
 1 │ rm 'test[].txt'
   ·    ──────┬─────
   ·          ╰── Pattern syntax error near position 40: invalid range pattern
   ╰────

but the mv command has a different error message:

nu✗ mv 'test[].txt' 'test2.txt'
Error: 
  × File(s) not found
   ╭─[entry #33:1:1]
 1 │ mv 'test[].txt' 'test2.txt'
   ·    ──────┬─────
   ·          ╰── could not find any files matching this glob pattern
   ╰────

the same happens if the [ ] is in the directory name:

nu✗ ls **/*
╭───┬───────────────────┬──────┬──────┬────────────────╮
│ # │       name        │ type │ size │    modified    │
├───┼───────────────────┼──────┼──────┼────────────────┤
│ 0 │ test.txt          │ file │ 13 B │ 40 minutes ago │
│ 1 │ test[]            │ dir  │ 36 B │ 11 seconds ago │
│ 2 │ test[]/test.txt   │ file │ 13 B │ 40 minutes ago │
│ 3 │ test[]/test[].txt │ file │ 13 B │ 40 minutes ago │
│ 4 │ test[].txt        │ file │ 13 B │ 40 minutes ago │
╰───┴───────────────────┴──────┴──────┴────────────────╯

nu❯ ls **/* | get name | get 2 | open
Error: 
  × Error extracting glob pattern
   ╭─[entry #52:1:1]
 1 │ ls **/* | get name | get 2 | open
   ·                              ──┬─
   ·                                ╰── Pattern syntax error near position 40: invalid range pattern
   ╰────

nu✗ open `test[]/test.txt`
Error: 
  × Error extracting glob pattern
   ╭─[entry #54:1:1]
 1 │ open `test[]/test.txt`
   · ──┬─
   ·   ╰── Pattern syntax error near position 40: invalid range pattern
   ╰────

I did also try to see if the issue also happens with () and {} and it didn`t.

How to reproduce

try to open a file that has [] in its name.

Expected behavior

the file to be opened if it is quoted or been passed as a string from a pipe.

Screenshots

No response

Configuration

key value
version 0.80.0
branch makepkg
commit_hash 8695b57
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.69.0 (84c898d65 2023-04-16) (Arch Linux rust 1:1.69.0-3)
cargo_version cargo 1.69.0
build_time 2023-05-17 05:13:57 +00:00
build_rust_channel release
features default, zip
installed_plugins

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:file-systemRelated to commands and core nushell behavior around the file systemA:globBehavior around file-system globbing with regular commands or `glob`. See also A:quoting/expansioncategory:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions