Spec-Zone.ru › Nushell

str expand for strings

Generates all possible combinations defined in brace expansion syntax.

Signature

> str expand {flags}

Flags

  • --path: Replaces all backslashes with double backslashes, useful for Path.

Input/output types:

input output
string list<string>
list<string> list<list<string>>

Examples

Define a range inside braces to produce a list of string.

> "{3..5}" | str expand
╭───┬───╮
│ 0 │ 3 │
│ 1 │ 4 │
│ 2 │ 5 │
╰───┴───╯

Ignore the next character after the backslash ('').

> 'A{B\,,C}' | str expand
╭───┬─────╮
│ 0 │ AB, │
│ 1 │ AC  │
╰───┴─────╯

Commas that are not inside any braces need to be skipped.

> 'Welcome\, {home,mon ami}!' | str expand
╭───┬───────────────────╮
│ 0 │ Welcome, home!    │
│ 1 │ Welcome, mon ami! │
╰───┴───────────────────╯

Use double backslashes to add a backslash.

> 'A{B\\,C}' | str expand
╭───┬─────╮
│ 0 │ AB\ │
│ 1 │ AC  │
╰───┴─────╯

Export comma separated values inside braces ({}) to a string list.

> "{apple,banana,cherry}" | str expand
╭───┬────────╮
│ 0 │ apple  │
│ 1 │ banana │
│ 2 │ cherry │
╰───┴────────╯

If the piped data is path, you may want to use --path flag, or else manually replace the backslashes with double backslashes.

> 'C:\{Users,Windows}' | str expand --path
╭───┬────────────╮
│ 0 │ C:\Users   │
│ 1 │ C:\Windows │
╰───┴────────────╯

Brace expressions can be used one after another.

> "A{b,c}D{e,f}G" | str expand
╭───┬───────╮
│ 0 │ AbDeG │
│ 1 │ AbDfG │
│ 2 │ AcDeG │
│ 3 │ AcDfG │
╰───┴───────╯

Collection may include an empty item. It can be put at the start of the list.

> "A{,B,C}" | str expand
╭───┬────╮
│ 0 │ A  │
│ 1 │ AB │
│ 2 │ AC │
╰───┴────╯

Empty item can be at the end of the collection.

> "A{B,C,}" | str expand
╭───┬────╮
│ 0 │ AB │
│ 1 │ AC │
│ 2 │ A  │
╰───┴────╯

Empty item can be in the middle of the collection.

> "A{B,,C}" | str expand
╭───┬────╮
│ 0 │ AB │
│ 1 │ A  │
│ 2 │ AC │
╰───┴────╯

Also, it is possible to use one inside another. Here is a real-world example, that creates files.

> "A{B{1,3},C{2,5}}D" | str expand
╭───┬──────╮
│ 0 │ AB1D │
│ 1 │ AB3D │
│ 2 │ AC2D │
│ 3 │ AC5D │
╰───┴──────╯

Supports zero padding in numeric ranges.

> "A{08..10}B{11..013}C" | str expand
╭───┬──────────╮
│ 0 │ A08B011C │
│ 1 │ A08B012C │
│ 2 │ A08B013C │
│ 3 │ A09B011C │
│ 4 │ A09B012C │
│ 5 │ A09B013C │
│ 6 │ A10B011C │
│ 7 │ A10B012C │
│ 8 │ A10B013C │
╰───┴──────────╯

Notes

This syntax may seem familiar with glob {A,B}.C. The difference is glob relies on filesystem, but str expand is not. Inside braces, we put variants. Then basically we're creating all possible outcomes.

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/str_expand.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API