You are not logged in.

#1 2020-08-26 23:28:28

regid
Member
Registered: 2016-06-06
Posts: 208

Does a systemd service always look for a ${} construct in the env?

Consider the following systemd unit:

[Unit]
Description=Is it looking for ${} construct in the wrong place?
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'set -x; declare -r str="1 2"; echo ${str}; echo $str; exit 0;'

After it is ran, the log has

bash[14190]: + declare -r 'str=1 2'
bash[14190]: + echo
bash[14190]: + echo 1 2
bash[14190]: 1 2
bash[14190]: + exit 0

Notice ${str} was not passed to one of the echo commands. Namely, the first echo command. Is this a bug, or am I doing something wrong?

I assume that is because systemd.service man page states

Basic environment variable substitution is supported. Use "${FOO}" ...

, so the ${} construct was not received by the shell. Which is a bug, because the that URL also states, at the same paragraph,

Use "$FOO" ...

And my example did not have any problems with $str.

In addition, the echo ${str}, which turned out to be just echo, doesn't have a matched empty line (just bash[14190]: ) in the log. Is that an optimization of the log?

Last edited by regid (2020-08-26 23:30:20)

Offline

#2 2020-08-27 20:52:46

regid
Member
Registered: 2016-06-06
Posts: 208

Re: Does a systemd service always look for a ${} construct in the env?

The issue was answered at a systemd mailing list thread start. And claimed to be as documented at the systemd.service man page.

Offline

Board footer

Powered by FluxBB