From de99fadd3117d2bbe3d5fdf1c6e7b6855fccf465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 3 Apr 2023 08:26:56 +0200 Subject: man/systemd-run: add examples explaining how variable expansion is performed --- man/systemd-run.xml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'man') 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 @@ -551,6 +551,42 @@ There is a screen on: $ loginctl enable-linger + + Variable expansion by the manager + + $ systemd-run -t echo "<${INVOCATION_ID}>" '<${INVOCATION_ID}>' + <> <5d0149bfa2c34b79bccb13074001eb20> + + + The first argument is expanded by the shell (double quotes), but the second one is not expanded + by the shell (single quotes). echo is called with [/usr/bin/echo, + [], [${INVOCATION_ID}]] as the argument array, and then + systemd generates ${INVOCATION_ID} 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. + + + + Variable expansion and output redirection using a shell + + Variable expansion by systemd can be disabled with + --expand-environment=no. + + 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: + + $ systemd-run --expand-environment=no -t bash \ + -c 'echo $SHELL $$ >/dev/stdout' +/bin/bash 12345 + + + The last argument is passed verbatim to the bash shell which is started by the + service unit. The shell expands $SHELL to the path of the shell, and + $$ to its process number, and then those strings are passed to the + echo built-in and printed to standard output (which in this case is connected to the + calling terminal). + + Return value -- cgit v1.2.1