]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/systemd-escape.xml
escape: support --unescape with --template
[thirdparty/systemd.git] / man / systemd-escape.xml
CommitLineData
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
83 <option>--suffix=</option> or
798d3a52
ZJS
84 <option>--mangle</option>.</para></listitem>
85 </varlistentry>
86
87 <varlistentry>
88 <term><option>--path</option></term>
89 <term><option>-p</option></term>
90
2651d037
LP
91 <listitem><para>When escaping or unescaping a string, assume it refers to a file system path. This eliminates
92 leading, trailing or duplicate <literal>/</literal> characters and rejects <literal>.</literal> and
93 <literal>..</literal> path components. This is particularly useful for generating strings suitable for
94 unescaping with the <literal>%f</literal> specifier in unit files, see
95 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
96 </para></listitem>
798d3a52
ZJS
97 </varlistentry>
98
99 <varlistentry>
100 <term><option>--unescape</option></term>
1a17bac5 101 <term><option>-u</option></term>
798d3a52
ZJS
102
103 <listitem><para>Instead of escaping the specified strings,
104 undo the escaping, reversing the operation. May not be used in
e563e253 105 conjunction with <option>--suffix=</option> or
798d3a52
ZJS
106 <option>--mangle</option>.</para></listitem>
107 </varlistentry>
108
109 <varlistentry>
110 <term><option>--mangle</option></term>
1a17bac5 111 <term><option>-m</option></term>
798d3a52
ZJS
112
113 <listitem><para>Like <option>--escape</option>, but only
114 escape characters that are obviously not escaped yet, and
115 possibly automatically append an appropriate unit type suffix
116 to the string. May not be used in conjunction with
117 <option>--suffix=</option>, <option>--template=</option> or
118 <option>--unescape</option>.</para></listitem>
119 </varlistentry>
120
121 <xi:include href="standard-options.xml" xpointer="help" />
122 <xi:include href="standard-options.xml" xpointer="version" />
123 </variablelist>
124
125 </refsect1>
126
127 <refsect1>
128 <title>Examples</title>
129
8bb36a11 130 <para>To escape a single string:</para>
798d3a52 131 <programlisting>$ systemd-escape 'Hallöchen, Meister'
9869e759
LP
132Hall\xc3\xb6chen\x2c\x20Meister</programlisting>
133
798d3a52
ZJS
134 <para>To undo escaping on a single string:</para>
135 <programlisting>$ systemd-escape -u 'Hall\xc3\xb6chen\x2c\x20Meister'
9869e759
LP
136Hallöchen, Meister</programlisting>
137
798d3a52
ZJS
138 <para>To generate the mount unit for a path:</para>
139 <programlisting>$ systemd-escape -p --suffix=mount "/tmp//waldi/foobar/"
9869e759
LP
140tmp-waldi-foobar.mount</programlisting>
141
8bb36a11 142 <para>To generate instance names of three strings:</para>
798d3a52 143 <programlisting>$ systemd-escape --template=systemd-nspawn@.service 'My Container 1' 'containerb' 'container/III'
9869e759 144systemd-nspawn@My\x20Container\x201.service systemd-nspawn@containerb.service systemd-nspawn@container-III.service</programlisting>
e563e253
LW
145
146 <para>To extract the instance part of an instantiated unit:</para>
147 <programlisting>$ systemd-escape -u --template=systemd-nspawn@.service 'systemd-nspawn@My\x20Container\x201.service'
148My Container 1</programlisting>
798d3a52
ZJS
149 </refsect1>
150
151 <refsect1>
152 <title>Exit status</title>
153
154 <para>On success, 0 is returned, a non-zero failure code
155 otherwise.</para>
156 </refsect1>
157
158 <refsect1>
159 <title>See Also</title>
160 <para>
161 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
2651d037 162 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
798d3a52
ZJS
163 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>
164 </para>
165 </refsect1>
9869e759
LP
166
167</refentry>