mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 20:25:12 +00:00
docs: Simplify Combining Lists section
This was a bit dense.
This commit is contained in:
parent
8bac13360b
commit
b6bebec513
1 changed files with 15 additions and 9 deletions
|
@ -922,19 +922,25 @@ To use a "," as an element, :ref:`quote <quotes>` or :ref:`escape <escapes>` it.
|
||||||
Combining lists
|
Combining lists
|
||||||
^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
When lists are expanded with other parts attached, they are expanded with these parts still attached. That means any string before a list will be concatenated to each element, and two lists will be expanded in all combinations - every element of the first with every element of the second.
|
Fish expands lists like :ref:`brace expansions <expand-brace>`::
|
||||||
|
|
||||||
This works basically like :ref:`brace expansion <expand-brace>`.
|
>_ set -l foo x y z
|
||||||
|
>_ echo 1$foo
|
||||||
|
# Any element of $foo is combined with the "1":
|
||||||
|
1x 1y 1z
|
||||||
|
|
||||||
Examples::
|
>_ echo {good,bad}" apples"
|
||||||
|
# Any element of the {} is combined with the " apples":
|
||||||
|
good apples bad apples
|
||||||
|
|
||||||
# Brace expansion is the most familiar:
|
# Or we can mix the two:
|
||||||
# All elements in the brace combine with
|
>_ echo {good,bad}" "$foo
|
||||||
# the parts outside of the braces
|
good x bad x good y bad y good z bad z
|
||||||
>_ echo {good,bad}" apples"
|
|
||||||
good apples bad apples
|
Any string attached to a list will be concatenated to each element.
|
||||||
|
|
||||||
|
Two lists will be expanded in all combinations - every element of the first with every element of the second::
|
||||||
|
|
||||||
# The same thing happens with variable expansion.
|
|
||||||
>_ set -l a x y z; set -l b 1 2 3
|
>_ set -l a x y z; set -l b 1 2 3
|
||||||
>_ echo $a$b # same as {x,y,z}{1,2,3}
|
>_ echo $a$b # same as {x,y,z}{1,2,3}
|
||||||
x1 y1 z1 x2 y2 z2 x3 y3 z3
|
x1 y1 z1 x2 y2 z2 x3 y3 z3
|
||||||
|
|
Loading…
Reference in a new issue