diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-04-03 08:26:56 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-04-24 10:02:30 +0200 |
commit | de99fadd3117d2bbe3d5fdf1c6e7b6855fccf465 (patch) | |
tree | ad7542c0556119301941c6874905db0cc3b49add /man/systemd-run.xml | |
parent | f872ddd182bd33d9ba0569d050374b9b9a9a2ab4 (diff) | |
download | systemd-de99fadd3117d2bbe3d5fdf1c6e7b6855fccf465.tar.gz |
man/systemd-run: add examples explaining how variable expansion is performed
Diffstat (limited to 'man/systemd-run.xml')
-rw-r--r-- | man/systemd-run.xml | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/man/systemd-run.xml b/man/systemd-run.xml index 2ad68d8884..f33190f4c5 100644 --- a/man/systemd-run.xml +++ b/man/systemd-run.xml @@ -552,6 +552,42 @@ There is a screen on: </example> <example> + <title>Variable expansion by the manager</title> + + <programlisting>$ systemd-run -t echo "<${INVOCATION_ID}>" '<${INVOCATION_ID}>' + <> <5d0149bfa2c34b79bccb13074001eb20> + </programlisting> + + <para>The first argument is expanded by the shell (double quotes), but the second one is not expanded + by the shell (single quotes). <command>echo</command> is called with [<literal>/usr/bin/echo</literal>, + <literal>[]</literal>, <literal>[${INVOCATION_ID}]</literal>] as the argument array, and then + <command>systemd</command> generates <varname>${INVOCATION_ID}</varname> and substitutes it in the + command-line. This substitution could not be done on the client side, because the target ID that will + be set for the service isn't known before the call is made.</para> + </example> + + <example> + <title>Variable expansion and output redirection using a shell</title> + + <para>Variable expansion by <command>systemd</command> can be disabled with + <varname>--expand-environment=no</varname>.</para> + + <para>Disabling variable expansion can be useful if the command to execute contains dollar characters + and escaping them would be inconvenient. For example, when a shell is used:</para> + + <programlisting>$ systemd-run --expand-environment=no -t bash \ + -c 'echo $SHELL $$ >/dev/stdout' +/bin/bash 12345 + </programlisting> + + <para>The last argument is passed verbatim to the <command>bash</command> shell which is started by the + service unit. The shell expands <literal>$SHELL</literal> to the path of the shell, and + <literal>$$</literal> to its process number, and then those strings are passed to the + <command>echo</command> built-in and printed to standard output (which in this case is connected to the + calling terminal).</para> + </example> + + <example> <title>Return value</title> <programlisting>$ systemd-run --user --wait true |