Home Explore Blog CI



nushell

1st chunk of `lang-guide/chapters/types/basic_types/glob.md`
497032955eb657d7c54052dd842c336dac6378a3c0d2cafa00000001000007fa
# Glob

<!-- prettier-ignore -->
|     |     |
| --- | --- |
| **_Description:_**    | A *pattern* that matches pathnames in a filesystem
| **_Annotation:_**     | `glob`                                                                                 
| **_Literal syntax:_** | None
| **_Casts:_**          | [`into glob`](/commands/docs/into_glob.md)
| **_See Also:_**       | [Moving around the system - Glob patterns](/book/moving_around.md#glob-patterns-wildcards) in the Book

## Additional Language Notes

1. A `glob` is similar to a string, but it is expanded to match files using a pattern.

1. Globs are implemented using the [nu_glob](https://docs.rs/nu-glob/latest/nu_glob/index.html) crate. The [possible glob patterns](https://docs.rs/nu-glob/latest/nu_glob/struct.Pattern.html) are documented there.

1. When a command accepts a glob pattern directly:

   - It will interpret a bare-word (or backtick-quoted) string as a glob. This means:
     ```nu
     open *.txt    # opens all files which ends with `.txt`
     open `*.txt`  # it's backtick quoted, it's a bare word, so nu opens all files which ends with `.txt`
     ```
   - It will interpret other string types as a string literal. This means:

     ```nu
     open "*.txt"  # it's quoted, opens a file named `*.txt`
     open '*.txt'  # it's quoted, opens a file named `*.txt`
     ```

1. There is no literal syntax for a glob. As seen above, it is usually created as a string and then interpreted by the calling command as a glob.

   Example

   <!-- TODO: Update example to use touch once it accepts glob properly -->
   <!-- touch can show the differences more tangibly -->

   ```nu
   let s = "a*c.txt"         # a string type.
   open $s                   # opens a file literally named `a*c.txt`

   let g: glob = "a*c.txt"   # a glob type.
   open $g                   # opens files matching the glob pattern, e.g: `abc.txt`, `aac.txt`
   ```

1. These expansions also take place with custom commands:

   ```nu
   # open files which match a given glob pattern

Title: Glob Type in Nushell
Summary
This section describes the `glob` type in Nushell, which is a pattern used to match pathnames in a filesystem. It explains how globs are similar to strings but are expanded to match files using a pattern, implemented via the `nu_glob` crate. It details how Nushell interprets bare-word strings as globs when a command directly accepts a glob pattern and clarifies that there is no literal syntax for a glob, as it's usually created as a string and interpreted by the calling command.