Skip to content

Error: File(s) not found when the name contains square brackets #10749

Closed

Description

@munzirtaha

Describe the bug

Using back-quoted filenames, I can use the touch command to create a file named [23].txt but I cannot remove it.

How to reproduce

~> touch `[23].mp4`
~> rm `[23].mp4`
Error:   × File(s) not found
   ╭─[entry #52:1:1]
 1 │ rm `[23].mp4`
   ·    ─────┬────
   ·         ╰── File(s) not found
   ╰────

Expected behavior

external commands should behave consistently with back-quoted strings

Screenshots

No response

Configuration

version | transpose key value | to md --pretty 10/18/23 02:13:53 AM
| key | value |
| ------------------ | ---------------------------------------------------------------- |
| version | 0.85.0 |
| branch | makepkg |
| commit_hash | a6f62e0 |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.72.1 (d5c2e9c34 2023-09-13) (Arch Linux rust 1:1.72.1-1) |
| cargo_version | cargo 1.72.1 |
| build_time | 2023-09-22 08:35:37 +00:00 |
| build_rust_channel | release |
| allocator | mimalloc |
| features | dataframe, default, extra, sqlite, trash, which, zip |
| installed_plugins

Additional context

No response

Activity

  1. added
    status:needs-triage
    on Oct 17, 2023
  2. fdncred commented on Oct 18, 2023

    @fdncred
    Contributor

    You have to escape glob characters. I think rm '[[]23].mp4' would probably work.

  3. munzirtaha commented on Oct 18, 2023

    @munzirtaha
    Author

    You have to escape glob characters. I think rm '[[]23].mp4' would probably work.

    No, it doesn't work.

  4. fdncred commented on Oct 18, 2023

    @fdncred
    Contributor

    No issues with the latest version.
    image

  5. munzirtaha commented on Oct 18, 2023

    @munzirtaha
    Author

    There is a new version 9 hours ago and I haven't tried it yet but still I see this as counter-intuitive.

    First, according to the documentation backtick-quoted and single-quoted strings don't do anything to the text they're given and escapes are none for them. the square brackets are not even mentioned as escape characters there.

    Second, this is counter-intuitive at least for Bourne-shell born human beings.

  6. bobhy commented on Oct 18, 2023

    @bobhy
    Contributor

    I have PR #10571 pending which would work the way you want.
    But before that PR is merged, @fdncred is correct -- you must escape glob metacharacters using glob quoting (which is [x], a character class that matches only 1 character). This does work as mentioned in recent builds.
    This behavior is different from bash, where the shell expands globs so you use shell escapes to quote metachars. In nushell, it's the individual command that decides whether to treat its argument as a glob pattern, so the single quotes only ensured none of the metacharacters were treated as Nushell tokens and you still need to tell rm that you don't want the glob expanded.

  7. mb21 commented on Oct 18, 2023

    @mb21

    Thansk @bobhy for your PR, that sounds indeed promising.
    I also just ran into this. Where is it documented what globs there are and that you can escape them with []? Didn't see anything here: https://www.nushell.sh/book/moving_around.html#glob-patterns-wildcards

    P.S. Especially confusing since tabbing seems to auto-complete it wrongly.

  8. added
    A:glob
    on Oct 18, 2023
  9. bobhy commented on Oct 18, 2023

    @bobhy
    Contributor

    Yep, no glob documentation in the book, perhaps you'd like to take a crack at writing it?

    Globbing for command arguments is done by an integrated fork of crate glob, their documentation is here: https://docs.rs/glob/0.3.1/glob/struct.Pattern.html

    FYI, and just to avoid potential confusion, the glob command uses a different, and more powerful, crate, wax.

  10. amtoine commented on Oct 18, 2023

    @amtoine
    Member

    actually, PR is #10694 and issue is #10571 😉

  11. amtoine commented on Oct 18, 2023

    @amtoine
    Member

    if #10694 does not solve this issue, please let me know 😌

  12. munzirtaha commented on Oct 18, 2023

    @munzirtaha
    Author

    Thanks all for the constructive and quick responses

  13. added this to the v0.87.0 milestone on Oct 19, 2023
  14. mb21 commented on Oct 23, 2023

    @mb21

    Yep, no glob documentation in the book, perhaps you'd like to take a crack at writing it?

    here you go :) nushell/nushell.github.io#1125

  15. mb21 commented on Oct 23, 2023

    @mb21

    @bobhy is it possible that #10694 omitted to fix the ls command? I just tried latest main and while I can rm '[23].mp4', I cannot ls '[23].mp4'.

    Also, tab-completion still completes to the wrong (unescaped) output (should I open a new issue for that?):

    Screen.Recording.2023-10-23.at.14.51.59.mov
  16. bobhy commented on Oct 23, 2023

    @bobhy
    Contributor
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:globstatus:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions