Thanks to Elias Probst's answer here, I'm using this to replace environment variables in a text file:
TARGET_FILE=/etc/apache2/apache2.conf;
for VARNAME in $(grep -P -o -e '\$\{\S+\}' ${TARGET_FILE} | sed -e 's|^\${||g' -e 's|}$||g' | sort -u);
do sed -i "s|\${$(echo $VARNAME)}|${!VARNAME}|g" ${TARGET_FILE};
done
I'd like this to be something that I could alias and pipe the templated file into and be able to have the replaced file written to standard out. I can imagine how to do this with a temporary file (copy the template to a temp file, run sed and let it replace in place, cat out the temp file), but I'd prefer to avoid that.
Any hints? Thank you!