mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 12:04:39 +08:00
docs: Reword quotes
Also explain that `$(foo)` is also done in double-quotes.
This commit is contained in:
parent
772a367365
commit
83d95cea35
|
@ -69,30 +69,31 @@ Here we define some of the terms used on this page and throughout the rest of th
|
|||
Quotes
|
||||
------
|
||||
|
||||
Sometimes features like :ref:`parameter expansion <expand>` and :ref:`character escapes <escapes>` get in the way. When that happens, you can use quotes, either single (``'``) or double (``"``). Between single quotes, fish performs no expansions. Between double quotes, fish only performs :ref:`variable expansion <expand-variable>`. No other kind of expansion (including :ref:`brace expansion <expand-brace>` or parameter expansion) is performed, and escape sequences (for example, ``\n``) are ignored. Within quotes, whitespace is not used to separate arguments, allowing quoted arguments to contain spaces.
|
||||
Sometimes you want to give a command an argument that contains characters special to fish, like spaces or ``$`` or ``*``. To do that, you can use quotes::
|
||||
|
||||
rm "my file.txt"
|
||||
|
||||
to remove a file called ``my file.txt`` instead of trying to remove two files, ``my`` and ``file.txt``.
|
||||
|
||||
Fish understands two kinds of quotes: Single (``'``) and double (``"``), and both work slightly differently.
|
||||
|
||||
Between single quotes, fish performs no expansions. Between double quotes, fish only performs :ref:`variable expansion <expand-variable>` and :ref:`command substitution <expand-command-substitution>` in the ``$(command)``. No other kind of expansion (including :ref:`brace expansion <expand-brace>` or parameter expansion) is performed, and escape sequences (for example, ``\n``) are ignored. Within quotes, whitespace is not used to separate arguments, allowing quoted arguments to contain spaces.
|
||||
|
||||
The only meaningful escape sequences in single quotes are ``\'``, which escapes a single quote and ``\\``, which escapes the backslash symbol. The only meaningful escapes in double quotes are ``\"``, which escapes a double quote, ``\$``, which escapes a dollar character, ``\`` followed by a newline, which deletes the backslash and the newline, and ``\\``, which escapes the backslash symbol.
|
||||
|
||||
Single quotes have no special meaning within double quotes and vice versa.
|
||||
|
||||
Example::
|
||||
|
||||
rm "cumbersome filename.txt"
|
||||
|
||||
removes the file ``cumbersome filename.txt``, while
|
||||
|
||||
::
|
||||
|
||||
rm cumbersome filename.txt
|
||||
|
||||
removes two files, ``cumbersome`` and ``filename.txt``.
|
||||
|
||||
Another example::
|
||||
More examples::
|
||||
|
||||
grep 'enabled)$' foo.txt
|
||||
|
||||
searches for lines ending in ``enabled)`` in ``foo.txt`` (the ``$`` is special to ``grep``: it matches the end of the line).
|
||||
|
||||
::
|
||||
apt install "postgres-*"
|
||||
|
||||
installs all packages with a name starting with "postgres-", instead of looking through the current directory for files named "postgres-something".
|
||||
|
||||
.. _escapes:
|
||||
|
||||
Escaping Characters
|
||||
|
|
Loading…
Reference in New Issue
Block a user