[systemd-devel] systemd environment variable handling and spaces bug?

Lennart Poettering lennart at poettering.net
Mon Jul 11 09:41:41 PDT 2011


On Mon, 11.07.11 16:49, Barry Scott (barry.scott at onelan.co.uk) wrote:

> I would like to take advantage of ${var} in the ExecStart lines.
> 
> However I find that there is a issue with handling of while space.
> 
> If I code this
> 
> 	ExecStart=/myservice --arg ${optional_arg}
> 
> If option_arg is not defined argv is ['/myservice', '--arg', '']
> Is it a bug that you do not strip trailing whitespace after substituion?
> 
> 
> If I code this
> 
> 	ExecStart=/myservice --arg${optional_arg}
> 
> and define
> 
> 	option_arg= --debug
> 
> argv is ['/myservice', '--arg--debug']
> Is it a bug that the whitespace after = was stripped?

systemd supports exactly two ways to resolve env vars.

a) You place ${FOO} as part of a word, or as word of its own on the
command line, in which case it will pre replaced by the value of the env
var -- and the value will *not* be split up at whitespace. Note the use
of {}!

b) You place $FOO as separate word on the command line, which means that
the this will be replaced by the value of the env var split up at
whitespace. Note that no {} is used for this syntax!

In either way the parser for EnvironmentFile= will strip leading and
trailing whitespace from the values of assignments, unless you use ""
quotes.

This is documented on systemd.service(5), under ExecStart=.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list