I'm designing a systemd service file for some plugin. I need to include two environment files there: first for the main program (let it be main.env), second — for the plugin (plugin.env). The plugin needs some variable VAR to be defined before it is started.

Sometimes users may want to define this variable in main.env, sometimes this variable may be missing, and actually I have no control on the environment file of the main program, this variable may be removed from it in the next release as non-obligatory.

So I want to provide a fallback value for the variable, but only in case it is not set yet. Also I want this fallback value to be actually defined in plugin.env so that users may change this value locally without losing it after update, and I use this variable at the same file to set next variables.

In bash, what I want looks like: : ${VAR:=fallback_value}. Is it possible to write this in systemd environment file?

I've looked through the manual (here), but, alas, found nothing relevant.

1 Answer 1


Environment=VAR=fallback_value makes what I want. Precisely:

  1. Defines VAR iff it is not defined in any environment file (actually just before reading config files, this value just gets overwritten if defined in these files)
  2. Makes it defined when including plugin.env so that I can define in this file smth like OPTION=${VAR}/value1 being sure that VAR is never empty.

ref, grep for «Environment=» there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .