[systemd-devel] How to source a variable file using systemd

Richard Maw richard.maw at codethink.co.uk
Tue Oct 27 03:41:50 PDT 2015


On Tue, Oct 27, 2015 at 04:05:18PM +0530, Soumya Koduri wrote:
<snip>
> EnvironmentFile=/etc/myconfig
> ....
> ExecStart=/bin/bash -c 'source ${MY_ENV_FILE} && echo ${MY_ENV_VAR}'

Systemd also does shell-like variable substitution, so potentially it's decided
to interpolate in the value of $MY_ENV_VAR before `source $MY_ENV_FILE` found
it.

Both those variables should be set in the environment appropriately when
ExecStart= is loaded, so I'd suggest escaping the $ as $$ so that bash gets to
do the interpolation instead of systemd.


More information about the systemd-devel mailing list