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