File: string-escape.rst

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (49 lines) | stat: -rw-r--r-- 1,776 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
string-escape - escape special characters
=========================================

Synopsis
--------

.. BEGIN SYNOPSIS

.. synopsis::

    string escape [-n | --no-quoted] [--style=] [STRING ...]
    string unescape [--style=] [STRING ...]

.. END SYNOPSIS

Description
-----------

.. BEGIN DESCRIPTION

``string escape`` escapes each *STRING* in one of several ways.

**--style=script** (default) alters the string such that it can be passed back to ``eval`` to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If **-n** or **--no-quoted** is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise.

**--style=var** ensures the string can be used as a variable name by hex encoding any non-alphanumeric characters. The string is first converted to UTF-8 before being encoded.

**--style=url** ensures the string can be used as a URL by hex encoding any character which is not legal in a URL. The string is first converted to UTF-8 before being encoded.

**--style=regex** escapes an input string for literal matching within a regex expression. The string is first converted to UTF-8 before being encoded.

``string unescape`` performs the inverse of the ``string escape`` command. If the string to be unescaped is not properly formatted it is ignored. For example, doing ``string unescape --style=var (string escape --style=var $str)`` will return the original string. There is no support for unescaping **--style=regex**.

.. END DESCRIPTION

Examples
--------

.. BEGIN EXAMPLES

::

    >_ echo \x07 | string escape
    \cg

    >_ string escape --style=var 'a1 b2'\u6161
    a1_20_b2_E6_85_A1_


.. END EXAMPLES