From: Zbigniew Jędrzejewski-Szmek Date: Mon, 3 Apr 2023 06:26:56 +0000 (+0200) Subject: man/systemd-run: add examples explaining how variable expansion is performed X-Git-Tag: v254-rc1~654^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de99fadd3117d2bbe3d5fdf1c6e7b6855fccf465;p=thirdparty%2Fsystemd.git man/systemd-run: add examples explaining how variable expansion is performed --- diff --git a/man/systemd-run.xml b/man/systemd-run.xml index 2ad68d8884c..f33190f4c58 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