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.envEnvronmentFile=/bar.envfoo.env:a=1#b=2c=3So I've thought adding to my bashrc something likeset -agrep EnvironmentFile /etc/systemd/system/foo.service | grep -v '^ *#' | cut -d'=' -f2 | xargs  -I {} bash -c 'source {};'set +aas specified in this answer.Is there a more elegant solution?
export all variables from EnvironmentFiles
bash;systemd;environment variables
This won't work at all because you're executing a new bash shell to do the 'source'Try:load_env() {  local files=( $(egrep '^[ ]*EnvironmentFile' $1 ) )  local f   set -a  for f in ${files[@]}  do     .   ${f##*=}   # this expression delete the EnvironmentFile= part  done  set +a}load_env /etc/systemd/system/foo.service