Repository navigation
Closed
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:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpectedhelp wantedstatus: Extra attention is needed
Milestone
Description
Describe the bug
The docs for ls say its pattern is:
pattern: the glob pattern to use
But its behavior is different than that of glob. ls with a glob pattern fails to find matching files, but glob with the same pattern finds them.
How to reproduce
mkdir a/b
touch a/b/foo.java
touch a/b/foo.class
mkdir a/b/c/d/e/f/g/h
touch a/b/c/d/e/f/g/h/bar.java
touch a/b/c/d/e/f/g/h/bar.class
# Finds all the files:
ls **/* | where type == file
# ls with glob does not find the files:
ls **/*.{class,java}
# But glob does:
glob **/*.{class,java}
Expected behavior
The thing documented as a glob should act as a glob.
Alternatively: if they are not equivalent, document the differences.
Screenshots
Or, in text:
/Users/codyc/test/nushell/glob-bug〉ls **/* | where type == file 12/22/2022 05:10:50 PM
╭───┬───────────────────────────┬──────┬──────┬───────────────╮
│ # │ name │ type │ size │ modified │
├───┼───────────────────────────┼──────┼──────┼───────────────┤
│ 0 │ a/b/c/d/e/f/g/h/bar.class │ file │ 0 B │ 2 minutes ago │
│ 1 │ a/b/c/d/e/f/g/h/bar.java │ file │ 0 B │ 2 minutes ago │
│ 2 │ a/b/foo.class │ file │ 0 B │ 3 minutes ago │
│ 3 │ a/b/foo.java │ file │ 0 B │ 3 minutes ago │
╰───┴───────────────────────────┴──────┴──────┴───────────────╯
/Users/codyc/test/nushell/glob-bug〉ls **/*.{class,java} 12/22/2022 05:10:54 PM
Error:
× No matches found for **/*.{class,java}
╭─[entry #36:1:1]
1 │ ls **/*.{class,java}
· ────────┬────────
· ╰── Pattern, file or folder not found
╰────
help: no matches found
/Users/codyc/test/nushell/glob-bug〉glob **/*.{class,java} 12/22/2022 05:11:12 PM
╭───┬──────────────────────────────────────────────────────────────╮
│ 0 │ /Users/codyc/test/nushell/glob-bug/a/b/foo.java │
│ 1 │ /Users/codyc/test/nushell/glob-bug/a/b/foo.class │
│ 2 │ /Users/codyc/test/nushell/glob-bug/a/b/c/d/e/f/g/h/bar.java │
│ 3 │ /Users/codyc/test/nushell/glob-bug/a/b/c/d/e/f/g/h/bar.class │
╰───┴──────────────────────────────────────────────────────────────╯
Configuration
| key | to |
|---|---|
| version | 0.73.0 |
| branch | |
| commit_hash | |
| build_os | macos-x86_64 |
| build_target | x86_64-apple-darwin |
| rust_version | rustc 1.65.0 |
| cargo_version | cargo 1.65.0 (4bc8f24d3 2022-10-20) |
| pkg_version | 0.73.0 |
| build_time | 2022-12-20 08:58:48 +00:00 |
| build_rust_channel | release |
| features | database, default, trash, which, zip |
| installed_plugins |
Additional context
Was very curious where my files went! 😆
Reacted by Akito, Reilly Wood, Lily, Míla Kuchta and Mariusz Pawelski
Reacted by Míla Kuchta
Metadata
Metadata
Assignees
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:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpectedhelp wantedstatus: Extra attention is needed

Activity
fdncred commentedon Dec 23, 2022
They use different globbing crates.
lsusesnu-globandglobuseswax. I wroteglobto usewaxbecausenu-globhad to be changed to support things inlsbetter. I thinkglobuses the more tradition pattern matching.rgwood commentedon Dec 23, 2022
This has come up in the context of
watchtoo. We should standardize on a single glob implementation eventually, just need to find a contributor with time on their hands :)fdncred commentedon Dec 23, 2022
I'd love to standardize on
waxand discontinuenu-globbut I can't really remember the exact reasons why we had to change it. I wouldn't want to remove it just to have the same problems withlsagain.skyvine commentedon Sep 24, 2023
Hello,
I see that this issue has the "help wanted" tag and there's an open question about the reason for nu-glob's existence.
The first commit touching the nu-glob directory references #4818 which states that the reason is to "remove the
[]syntax that is causing problems with users expecting more traditional globs". I eyeball-compared thecrates/nu-glob/src/lib.rsfrom that PR (3ea0e66) with the upstream one (https://docs.rs/crate/glob/latest/source/src/lib.rs), and the match inimpl Pattern { fn new(...) { ... } }is missing the[case which exists on upstream. Perhaps there were other changes, but this seems to satisfy the reason stated in the pull request. I'm not sure if the upstream glob has been updated since the fork. The PR is referenced by #4811, which was created a day before the pull request, so I am assuming that this is the only issue that caused this change in the first place. If @jntrnr is still active on this project perhaps they remember additional context, although this did happen a year and a half ago.I am interested in working on this issue. Additionally, I believe it is a blocker for #10364 for reasons explained in my comment on that issue. With the context of the above paragraph, I think it is safe to proceed with this change: the problem that caused the creation of
nu_globwas the inability to use square braces literally, and Wax supports backslash escapes (nu_globsupports escaping by surrounding special characters with square braces, but this is rather esoteric ).However, I am not sure if the above comment about standardizing on Wax was an offhand remark or if the project is certain that Wax is the library to standardize on. In either case, I do think that it would be useful to maintain a
nu_globcrate as an interface to globbing for the rest of the project. This will be helpful if the backend needs to change in the future, and if embedding is a use-case that the project cares about then it may be useful to embedders, as their application might use a different globbing engine and they would want a unified experience for their users. This approach will require to changes in theglobcommand, but based on its user-visible behavior (take in a glob, return the list of matches) I do not expect this to be a significant source of problems.I have spent a couple of days looking at the nushell source code to assess whether or not I had the capacity to make these kinds of changes (I was mostly focused on #10364, because I originally believed that was a blocker for this issue). I am confident that I can make this change, however I would appreciate feedback from a maintainer before I put more time into nushell.
Thanks,
Sklyer
fdncred commentedon Sep 25, 2023
@skyvine I tried to sync nu-glob and glob up within the past few months, but may have missed some areas or they've added more/different functionality/bug fixes. I'd be fine with removing nu-glob entirely if glob works better now. I added the
[]back in to see if someone could fix the problem. My reasoning was, if we continually hide the issue, it'll never be fixed and having the globbing[]syntax is important. If there's some simple change to nu-glob that would fix these problems, we'd accept the PR.Related to wax, I added it with the
globcommand to try and have better globbing (multiple inputs (although not supported yet), multiple nots, a little different syntax). At the time, it seemed to be the best globbing crate. Since then, it doesn't seem to be supported very well. I'd be supportive of unifying all our globbing on some well supported crate, assuming we don't lose a ton of functionality or performance. nu-glob/glob is pretty fast. I'd also be willing to entertain usingjwalkforlssince it will stream sorted and is able to use multiple threads. I've written 4 different branches to makelsbetter with different crates likejwalkand never finished any of them to my liking.skyvine commentedon Sep 26, 2023
Regarding curly brace behavior, one specific example of the inconsistency problem, Wax adds the curly braces as an unusual extension to what has historically been referred to as globbing. Curly brace expansion is a separate feature in traditional shells like Bash (brace expansion, filename expansion aka globbing) and Zsh (brace expansion, filename expansion aka globbing). Personally, I don't see any reason why nushell needs to conform to this specific precedent, although I'm also new to the project.
One thing that I am thinking about is the silver searcher. It is typically a grep replacement, but with the
-gflag it matches filenames (including the path, relative to the input) instead of contents. This means that the same regex syntax can be applied to both use-cases (file content searching and filename searching) which I personally find to be more ergonomic than using different pattern-matching syntaxes in different contexts. It would be possible to implement this with jwalk. Rust's built-in regex crate intentionally excludes some features in order to minimize the worst-case complexity which sounds like a tradeoff that the project would favor. An initial implementation would be straightforward in theory, as jwalk's process_read_dir lets us filter based on the path, so we can just walk everything and check the regex.However, the above approach would be very surprising to users coming from traditional shells because regexes are not path-aware (for example,
.*would match the path separator). It might be possible to process the regexes in a path-aware way, but I'm suspicious that this would add an excessive amount of complexity both in terms of readability and runtime performance. A more conservative approach would be to add curly-brace expansion tonu_glob. It is possible that there will still be some inconsistencies compared to performing curly-brace expansion and filename expansion in separate phases, but it is a less significant departure compared to abandoning globs all together in favor of regexes.fdncred commentedon Sep 27, 2023
I'm not super worried about brace expansion because we have
str expandthat does that. I'm more concerned about files or folders with[]in their names making file operations puke.One problem with the current implementation is that
lsis slow. You can really see that when using network drives or going from WSL to Windows drives. Having a multithreaded ability is helpful in these situations. I have a closed PR here somewhere with the one I wrote but the problem was that it was non-deterministic in it's sort, which could turn off users and after I made it sort, i resorted to collecting which broke the streaming rules. However, the test made it very clear that multithreaded behavior was superior as far as speed is concerned.skyvine commentedon Sep 27, 2023
Ok, then I think that the issue described in this report is working as intended. Please let me know if anything below is inaccurate:
It is expected that the
globandlscommands return different results.globwas added a an experimentallsalternative, so it would not make sense for it to behave identically. Unfortunately, the main dependency of theglobcommand is no longer maintained, so it will never be used for commands which take globs as inputs.Technically, I suppose the
globcommand should be deprecated/removed due to the above.fdncred commentedon Sep 27, 2023
to be clear, there's a
globcrate,nu-globcrate, andglobcommand. theglobcommand was never intended to be alsreplacement/alternative. it was to fill a gap thatlscouldn't provide, which was to do better globbing. we forked theglobcrate in the pr you found to makenu-globbut then restricted the globbing capabilities. i really want to have our cake and eat it too.I do agree with your point that the
globcommand andlsglobbing was never supposed to work identically. that was never the intent. quite the opposite. So, yes, the two crates are working independently as intended. However, I definitely want to have better globbing support inls, without confusion. I'm not sure what form that will take, but that's the goal. If we can get proper globbing inls, we may end-of-life theglobcommand.ErichDonGubler commentedon Sep 28, 2023
ICYMI: The maintainer of
waxhas expressed intent to continue maintaining after a lull and ping in issues: olson-sean-k/wax#45 (comment)fdncred commentedon Sep 28, 2023
I hope they do keep maintaining it. It's a nice crate.
c-git commentedon Feb 17, 2026
Bumped into this while going through the Getting started
Wasn't sure if I should mention it but it brought me here as I was quite surprised so sharing in case it makes it easier for the next person to find. I kinda had to look through a lot of issues to find this one. It's a bit surprising when you bump into unexpected results in the getting started.
As text:
fdncred commentedon Feb 17, 2026
I'm wondering if there's a typo that I'm missing or something because it all works for me. Maybe I'm missing the whole point?
c-git commentedon Feb 17, 2026
No I think you just missed
3. Force glob type via annotation:from the documentationThe ones you tried also work for me. The 3rd one gives me an error
fdncred commentedon Feb 17, 2026
oh, i see. it's because quotes fall through to the DoNotExpand part. It's like doing
ls *vsls "*". Seems like a bug, but of course, the work-around is to just do| into glob.The key is
lsis trying to know when you're literally looking for*and when it's a glob but for some reason, it doesn't see thatlet gp: glob = some_globis really a glob even thoughdescribethinks it is.c-git commentedon Feb 18, 2026
Maybe "hide" / "temporarily remove" the 3rd way from the docs until it works as described? I think 2 ways is plenty enough without sending the reader into the weeds.
fdncred commentedon Feb 18, 2026
hopefully this #17596 fixes the problem
c-git commentedon Feb 25, 2026
Should I install from the main branch to test for you? And if yes is it as simple as
cargo install --git https://github.com/nushell/nushell