From 8428247f31f6d54349f7d9508b4a808f243fe24e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 28 Oct 2021 16:48:08 +0200 Subject: [PATCH] docs: Split up the variable docs some more (also remove some broken or incorrect footnotes) --- doc_src/language.rst | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc_src/language.rst b/doc_src/language.rst index 9f78a218c..d62350046 100644 --- a/doc_src/language.rst +++ b/doc_src/language.rst @@ -491,8 +491,6 @@ Unlike bash (by default), fish will not pass on the literal glob character if no apt install "ncurses-*" -.. [#] Technically, unix allows filenames with newlines, and this splits the ``find`` output on newlines. If you want to avoid that, use find's ``-print0`` option and :ref:`string split0`. - .. _expand-variable: Variable expansion @@ -534,6 +532,9 @@ The latter syntax ``{$WORD}`` is a special case of :ref:`brace expansion ` - in that case it will use a colon (`:`) instead [#]_. Outside of double quotes, variables will expand to as many arguments as they have elements. That means an empty list will expand to nothing, a variable with one element will expand to that element, and a variable with multiple elements will expand to each of those elements separately. @@ -561,6 +562,11 @@ That means quoting isn't the absolute necessity it is in other shells. Most of t # works, because it was executed like test -n "one two three" +.. [#] Unlike bash or zsh, which will join with the first character of $IFS (which usually is space). + +Derefencing variables +''''''''''''''''''''' + The ``$`` symbol can also be used multiple times, as a kind of "dereference" operator (the ``*`` in C or C++), like in the following code:: set foo a b c @@ -578,8 +584,6 @@ The ``$`` symbol can also be used multiple times, as a kind of "dereference" ope When using this feature together with list brackets, the brackets will be used from the inside out. ``$$foo[5]`` will use the fifth element of ``$foo`` as a variable name, instead of giving the fifth element of all the variables $foo refers to. That would instead be expressed as ``$$foo[1..-1][5]`` (take all elements of ``$foo``, use them as variable names, then give the fifth element of those). -.. [#] Unlike bash or zsh, which will join with the first character of $IFS (which usually is space). - .. _expand-command-substitution: Command substitution @@ -620,7 +624,7 @@ Sometimes you want to pass the output of a command to another command that only grep fish myanimallist1 | wc -l -but if you need multiple or the command doesn't read from standard input, "process substitution" is useful. Other shells [#]_ allow this via ``foo <(bar) <(baz)``, and fish uses the :ref:`psub ` command:: +but if you need multiple or the command doesn't read from standard input, "process substitution" is useful. Other shells allow this via ``foo <(bar) <(baz)``, and fish uses the :ref:`psub ` command:: # Compare just the lines containing "fish" in two files: diff -u (grep fish myanimallist1 | psub) (grep fish myanimallist2 | psub) @@ -628,7 +632,6 @@ but if you need multiple or the command doesn't read from standard input, "proce This creates a temporary file, stores the output of the command in that file and prints the filename, so it is given to the outer command. .. [#] Setting ``$IFS`` to empty will disable line splitting. This is deprecated, use :ref:`string split ` instead. -.. [#] Bash and Zsh at least, though it is a POSIX extension .. _expand-brace: