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