Skip to content

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

Closed

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

Activity

  1. added
    status:needs-triage
    on May 28, 2023
  2. WindSoilder commented on May 28, 2023

    @WindSoilder
    Contributor

    Here is a pr to fix it: #9307

  3. added
    A:file-system
    and removed
    status:needs-triage
    on May 28, 2023
  4. linked a pull request that will close this issueAdd nullglob functionality to nu-glob #9307on May 28, 2023
  5. amtoine commented on May 28, 2023

    @amtoine
    Member

    as you suggested @WindSoilder, i've linked to #9307 👍
    if it's not a fixing PR in the end, we can unlink it 😉

  6. kurokirasama commented on Jun 7, 2023

    @kurokirasama
    Contributor

    Just add that I get this error too:

    could not find any files matching this glob pattern
    
  7. ynhame commented on Jun 7, 2023

    @ynhame
    Author

    Just add that I get this error too:

    I think it would help to also add the command that gave you this error.

    also the nushell version would be helpfull as well

  8. kurokirasama commented on Jun 7, 2023

    @kurokirasama
    Contributor
    touch "[a]b.c"
    
    cp `[a]b.c` ab.c
    (no matches found)
    
    mv `[a]b.c` ab.c
    (could not find any files matching this glob pattern)
    
    rm `[a]b.c`
    (File(s) not found)
    
    open `[a]b.c`
    (gives no error but doesn't show content)
    
  9. added
    category:bug
    on Jun 7, 2023
  10. ckafi commented on Jun 9, 2023

    @ckafi

    It seems this bug isn't limited to square brackets, but happens also with other glob patterns:

    touch '*' a b
    
    ls '*'
    ╭───┬──────┬──────┬──────┬──────────╮
    │ # │ name │ type │ size │ modified │
    ├───┼──────┼──────┼──────┼──────────┤
    │ 0 │ *    │ file │  0 B │ now      │
    │ 1 │ a    │ file │  0 B │ now      │
    │ 2 │ b    │ file │  0 B │ now      │
    ╰───┴──────┴──────┴──────┴──────────╯
    
    rm -v '*'
    deleted *
    deleted a
    deleted b
    
  11. ryanolsonx commented on Jun 14, 2023

    @ryanolsonx

    This also happens if a directory name has [ in it. This is popular in Next.js projects where directory structure dictates route.

    ~/c/app/src/pages/products/[id]> ls     1 06/14/2023 02:03:15 PM
    Error:   × No matches found for *
       ╭─[entry #35:1:1]
     1 │ ls
       · ─┬
       ·  ╰── Pattern, file or folder not found
       ╰────
      help: no matches found
    
  12. added
    A:glob
    on Jul 9, 2023
  13. star-szr commented on Aug 17, 2023

    @star-szr

    Looks like the latest related PR is #9416.

  14. linked a pull request that will close this issueAllow escaping glob with `\` in `nu-glob` #10246on Sep 6, 2023
  15. bobhy commented on Oct 10, 2023

    @bobhy
    Contributor

    I believe this is also fixed by #10557.

  16. aidalgol commented on Jan 11, 2024

    @aidalgol

    I am able to use the built-in Nushell commands (rm, mv, cp, etc.) on files with square brackets in the name as of Nushell 0.88, so this does appear to be fixed.

  17. ckafi commented on Jan 11, 2024

    @ckafi

    As of 0.89.0 it is not completely fixed. There is still some weirdness going on:

    nu> 'lorem' | save 'a'
    nu> 'ipsum' | save 'b'
    nu> 'dolor' | save '*'
    nu> 'sit' | save 'test[]'
    
    nu> ls
    ╭───┬────────┬──────┬──────┬───────────╮
    │ # │  name  │ type │ size │  modified │
    ├───┼────────┼──────┼──────┼───────────┤
    │ 0 │ *      │ file │  5 B │  now      │
    │ 1 │ a      │ file │  5 B │  now      │
    │ 2 │ b      │ file │  5 B │  now      │
    │ 3 │ test[] │ file │  3 B │  now      │
    ╰───┴────────┴──────┴──────┴───────────╯
    
    nu> ls '*'
    ╭───┬────────┬──────┬──────┬───────────╮
    │ # │  name  │ type │ size │  modified │
    ├───┼────────┼──────┼──────┼───────────┤
    │ 0 │ *      │ file │  5 B │  now      │
    │ 1 │ a      │ file │  5 B │  now      │
    │ 2 │ b      │ file │  5 B │  now      │
    │ 3 │ test[] │ file │  3 B │  now      │
    ╰───┴────────┴──────┴──────┴───────────╯
    
    nu> open '*'
    ╭───┬───────╮
    │ 0 │ dolor │
    │ 1 │ lorem │
    │ 2 │ ipsum │
    │ 3 │ sit   │
    ╰───┴───────╯
    
    nu> ls 'test[]'
    Error:   × Error extracting glob pattern
       ╭─[entry #92:1:1]
     1 │ ls 'test[]'
       · ─┬
       ·  ╰── Pattern syntax error near position 13: invalid range pattern
       ╰────
    
    nu> open 'test[]'
    Error:   × Error extracting glob pattern
       ╭─[entry #93:1:1]
     1 │ open 'test[]'
       · ──┬─
       ·   ╰── Pattern syntax error near position 13: invalid range pattern
       ╰────
    
    nu> rm -v *
    deleted /tmp/test/*
    
    nu> rm -v *
    deleted /tmp/test/b
    deleted /tmp/test/test[]
    deleted /tmp/test/a
    

    Similar issues exist if the path contains a glob pattern:

    nu> mkdir 'test[]'; cd 'test[]'
    nu> touch a b c
    nu> ls
    ╭───┬──────┬──────┬──────┬──────────╮
    │ # │ name │ type │ size │ modified │
    ├───┼──────┼──────┼──────┼──────────┤
    │ 0 │ a    │ file │  0 B │ now      │
    │ 1 │ b    │ file │  0 B │ now      │
    │ 2 │ c    │ file │  0 B │ now      │
    ╰───┴──────┴──────┴──────┴──────────╯
    
    nu> ls a
    Error:   × Error extracting glob pattern
       ╭─[entry #130:1:1]
     1 │ ls a
       · ─┬
       ·  ╰── Pattern syntax error near position 13: invalid range pattern
       ╰────
    
    nu> open a
    Error:   × Error extracting glob pattern
       ╭─[entry #131:1:1]
     1 │ open a
       · ──┬─
       ·   ╰── Pattern syntax error near position 13: invalid range pattern
       ╰────
    
    nu> rm -v *
    Error:   × Invalid glob pattern
       ╭─[entry #132:1:1]
     1 │ rm -v *
       ·       ┬
       ·       ╰── Invalid glob pattern
       ╰────
    
    nu> rm -v a b c
    deleted /tmp/test/test[]/c
    deleted /tmp/test/test[]/a
    deleted /tmp/test/test[]/b
    
  18. added a commit that references this issue on Jan 26, 2024
    d646903
  19. added this to the v0.90.0 milestone on Jan 26, 2024
  20. added a commit that references this issue on Feb 20, 2024
    549cee9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:file-systemA:globcategory:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions