I'd like to export all variables used by a certain systemd service, and are specified in its unit file using EnvironmentFile.
E.g. foo.service :
[Service]
...
EnvronmentFile=/foo.env
EnvronmentFile=/bar.env
foo.env:
a=1
#b=2
c=3
So I've thought adding to my bashrc something like
set -a
grep EnvironmentFile /etc/systemd/system/foo.service | grep -v '^ *#' | cut -d'=' -f2 | xargs -I {} bash -c 'source {};'
set +a
as specified in this answer.
Is there a more elegant solution?