]>
Commit | Line | Data |
---|---|---|
9869e759 LP |
1 | <?xml version='1.0'?> <!--*-nxml-*--> |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" | |
12b42c76 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
9869e759 LP |
4 | |
5 | <!-- | |
572eb058 | 6 | SPDX-License-Identifier: LGPL-2.1+ |
9869e759 LP |
7 | --> |
8 | ||
9 | <refentry id="systemd-escape" | |
798d3a52 ZJS |
10 | xmlns:xi="http://www.w3.org/2001/XInclude"> |
11 | ||
12 | <refentryinfo> | |
13 | <title>systemd-escape</title> | |
14 | <productname>systemd</productname> | |
798d3a52 ZJS |
15 | </refentryinfo> |
16 | ||
17 | <refmeta> | |
18 | <refentrytitle>systemd-escape</refentrytitle> | |
19 | <manvolnum>1</manvolnum> | |
20 | </refmeta> | |
21 | ||
22 | <refnamediv> | |
23 | <refname>systemd-escape</refname> | |
ab7e3ef5 | 24 | <refpurpose>Escape strings for usage in systemd unit names</refpurpose> |
798d3a52 ZJS |
25 | </refnamediv> |
26 | ||
27 | <refsynopsisdiv> | |
28 | <cmdsynopsis> | |
29 | <command>systemd-escape</command> | |
30 | <arg choice="opt" rep="repeat">OPTIONS</arg> | |
31 | <arg choice="opt" rep="repeat">STRING</arg> | |
32 | </cmdsynopsis> | |
33 | </refsynopsisdiv> | |
34 | ||
35 | <refsect1> | |
36 | <title>Description</title> | |
37 | ||
38 | <para><command>systemd-escape</command> may be used to escape | |
39 | strings for inclusion in systemd unit names. The command may be | |
40 | used to escape and to undo escaping of strings.</para> | |
41 | ||
42 | <para>The command takes any number of strings on the command line, | |
cd72d204 | 43 | and will process them individually, one after another. It will |
798d3a52 ZJS |
44 | output them separated by spaces to stdout.</para> |
45 | ||
b938cb90 | 46 | <para>By default, this command will escape the strings passed, |
798d3a52 | 47 | unless <option>--unescape</option> is passed which results in the |
a8eaaee7 JE |
48 | inverse operation being applied. If <option>--mangle</option> is given, a |
49 | special mode of escaping is applied instead, which assumes the | |
50 | string is already escaped but will escape everything that | |
798d3a52 | 51 | appears obviously non-escaped.</para> |
2651d037 LP |
52 | |
53 | <para>For details on the escaping and unescaping algorithms see the relevant section in | |
54 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> | |
798d3a52 ZJS |
55 | </refsect1> |
56 | ||
57 | <refsect1> | |
58 | <title>Options</title> | |
59 | ||
60 | <para>The following options are understood:</para> | |
61 | ||
62 | <variablelist> | |
63 | <varlistentry> | |
64 | <term><option>--suffix=</option></term> | |
65 | ||
66 | <listitem><para>Appends the specified unit type suffix to the | |
67 | escaped string. Takes one of the unit types supported by | |
2a75df74 LW |
68 | systemd, such as <literal>service</literal> or |
69 | <literal>mount</literal>. May not be used in conjunction with | |
798d3a52 ZJS |
70 | <option>--template=</option>, <option>--unescape</option> or |
71 | <option>--mangle</option>.</para></listitem> | |
72 | </varlistentry> | |
73 | ||
74 | <varlistentry> | |
75 | <term><option>--template=</option></term> | |
76 | ||
77 | <listitem><para>Inserts the escaped strings in a unit name | |
78 | template. Takes a unit name template such as | |
e563e253 LW |
79 | <filename>foobar@.service</filename>. With |
80 | <option>--unescape</option>, expects instantiated unit names | |
81 | for this template and extracts and unescapes just the instance | |
82 | part. May not be used in conjunction with | |
d936cddc LW |
83 | <option>--suffix=</option>, |
84 | <option>--instance</option> or | |
798d3a52 ZJS |
85 | <option>--mangle</option>.</para></listitem> |
86 | </varlistentry> | |
87 | ||
88 | <varlistentry> | |
89 | <term><option>--path</option></term> | |
90 | <term><option>-p</option></term> | |
91 | ||
2651d037 LP |
92 | <listitem><para>When escaping or unescaping a string, assume it refers to a file system path. This eliminates |
93 | leading, trailing or duplicate <literal>/</literal> characters and rejects <literal>.</literal> and | |
94 | <literal>..</literal> path components. This is particularly useful for generating strings suitable for | |
95 | unescaping with the <literal>%f</literal> specifier in unit files, see | |
96 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>. | |
97 | </para></listitem> | |
798d3a52 ZJS |
98 | </varlistentry> |
99 | ||
100 | <varlistentry> | |
101 | <term><option>--unescape</option></term> | |
1a17bac5 | 102 | <term><option>-u</option></term> |
798d3a52 ZJS |
103 | |
104 | <listitem><para>Instead of escaping the specified strings, | |
105 | undo the escaping, reversing the operation. May not be used in | |
e563e253 | 106 | conjunction with <option>--suffix=</option> or |
798d3a52 ZJS |
107 | <option>--mangle</option>.</para></listitem> |
108 | </varlistentry> | |
109 | ||
110 | <varlistentry> | |
111 | <term><option>--mangle</option></term> | |
1a17bac5 | 112 | <term><option>-m</option></term> |
798d3a52 ZJS |
113 | |
114 | <listitem><para>Like <option>--escape</option>, but only | |
115 | escape characters that are obviously not escaped yet, and | |
116 | possibly automatically append an appropriate unit type suffix | |
117 | to the string. May not be used in conjunction with | |
118 | <option>--suffix=</option>, <option>--template=</option> or | |
119 | <option>--unescape</option>.</para></listitem> | |
120 | </varlistentry> | |
121 | ||
d936cddc LW |
122 | <varlistentry> |
123 | <term><option>--instance</option></term> | |
124 | ||
125 | <listitem><para>With <option>--unescape</option>, unescape | |
126 | and print only the instance part of an instantiated unit name | |
127 | template. Results in an error for an uninstantiated template | |
128 | like <filename>ssh@.service</filename> or a non-template name | |
129 | like <filename>ssh.service</filename>. | |
130 | Must be used in conjunction with <option>--unescape</option> | |
131 | and may not be used in conjunction with | |
132 | <option>--template</option>.</para></listitem> | |
133 | </varlistentry> | |
134 | ||
798d3a52 ZJS |
135 | <xi:include href="standard-options.xml" xpointer="help" /> |
136 | <xi:include href="standard-options.xml" xpointer="version" /> | |
137 | </variablelist> | |
138 | ||
139 | </refsect1> | |
140 | ||
141 | <refsect1> | |
142 | <title>Examples</title> | |
143 | ||
8bb36a11 | 144 | <para>To escape a single string:</para> |
798d3a52 | 145 | <programlisting>$ systemd-escape 'Hallöchen, Meister' |
9869e759 LP |
146 | Hall\xc3\xb6chen\x2c\x20Meister</programlisting> |
147 | ||
798d3a52 ZJS |
148 | <para>To undo escaping on a single string:</para> |
149 | <programlisting>$ systemd-escape -u 'Hall\xc3\xb6chen\x2c\x20Meister' | |
9869e759 LP |
150 | Hallöchen, Meister</programlisting> |
151 | ||
798d3a52 ZJS |
152 | <para>To generate the mount unit for a path:</para> |
153 | <programlisting>$ systemd-escape -p --suffix=mount "/tmp//waldi/foobar/" | |
9869e759 LP |
154 | tmp-waldi-foobar.mount</programlisting> |
155 | ||
8bb36a11 | 156 | <para>To generate instance names of three strings:</para> |
798d3a52 | 157 | <programlisting>$ systemd-escape --template=systemd-nspawn@.service 'My Container 1' 'containerb' 'container/III' |
9869e759 | 158 | systemd-nspawn@My\x20Container\x201.service systemd-nspawn@containerb.service systemd-nspawn@container-III.service</programlisting> |
e563e253 LW |
159 | |
160 | <para>To extract the instance part of an instantiated unit:</para> | |
d936cddc LW |
161 | <programlisting>$ systemd-escape -u --instance 'systemd-nspawn@My\x20Container\x201.service' |
162 | My Container 1</programlisting> | |
163 | ||
164 | <para>To extract the instance part of an instance of a particular template:</para> | |
e563e253 LW |
165 | <programlisting>$ systemd-escape -u --template=systemd-nspawn@.service 'systemd-nspawn@My\x20Container\x201.service' |
166 | My Container 1</programlisting> | |
798d3a52 ZJS |
167 | </refsect1> |
168 | ||
169 | <refsect1> | |
170 | <title>Exit status</title> | |
171 | ||
172 | <para>On success, 0 is returned, a non-zero failure code | |
173 | otherwise.</para> | |
174 | </refsect1> | |
175 | ||
176 | <refsect1> | |
177 | <title>See Also</title> | |
178 | <para> | |
179 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
2651d037 | 180 | <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>, |
798d3a52 ZJS |
181 | <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
182 | </para> | |
183 | </refsect1> | |
9869e759 LP |
184 | |
185 | </refentry> |