How can I use spaces in systemd command line arguments?

As Nico suggested, you can create an EvironmentFile in which you can specify an argument with spaces.

SPACEYARG="i love spaces"

In your unit file however, you'll need to wrap that argument in curly brackets in order for the spaces to be passed properly.

EnvironmentFile=/etc/.progconf
ExecStart = command ${SPACEYARG}

This is actually surprisingly difficult to do, unfortunately. I stole this info from this answer. The only way to do it is to put your arguments in an environment file and then use them as variables as such (like in /etc/.progconfig):

ARG1=text
ARG2=text

Then import the environment file before running your command:

EnvironmentFile=/etc/.progconf
ExecStart = command $ARG1 $ARG2

systemd only seems to recognize quotes which fully wrap arguments; i.e.

ExecStart=command "--argument=text text"

works but

ExecStart=command --argument="text text"

does not. I just ran into this issue and filed #624 about it.

Tags:

Systemd