Jerry Bian
Jerry Bian

Reputation: 4238

How to write systemd environment variables value which contains =

In systemd units file, I have a Environment which content is key=IamValue=abc, as you can see the value is IamValue=abc which contains =.

For this situation, how can I write the unit files?

I have tried as following, but it seems invalid:

[Unit]
Description=...

[Service]
WorkingDirectory=...
ExecStart=...
Restart=always
RestartSec=10                                          
SyslogIdentifier=...
User=root
Environment=key="IamValue=abc"

Upvotes: 5

Views: 4398

Answers (2)

shizhz
shizhz

Reputation: 12501

Alternatively use EnvironmentFile, config line in unit file:

EnvironmentFile=-/etc/sysconfig/test

With content in /etc/sysconfig/test:

key="IamValue=abc"

Upvotes: 1

Mark Stosberg
Mark Stosberg

Reputation: 13381

I tested that this works in a test.service file:

[Unit]
Description=Hi

[Service]
Type=oneshot
Environment=key="IamValue=abc"
ExecStart=/bin/bash -c "/bin/echo key:$key"

If you run that and then do journalctl -u test, you can see the key containing the equal sign works.

I've proposed an update to the official systemd docs to better clarify this case.

Upvotes: 6

Related Questions