I am interested if there is a UNIX tool which replaces occurences of $VAR
or ${VAR}
(for all existing variables in the env, not just one) with the actual values of environment variables. This replacment is in a plain text file, not a bash script; a "poor man's template engine" of sort.
I know I can do
(echo 'echo -n "'; sed -e "s/\"/\"'\"'\"/g" infile; echo '"') | sh -s >outfile
(I do, in fact), but if there is a well-known tool for that, I'd rather use it instead of clever sh
tricks.
EDIT: @glennjackman suggest use of eval
, so the line is shorter and without subshell:
eval echo -n \""`sed -e 's/"/\\\\\\\"/g' infile`"\" >outfile
which is pretty short (though not a dedicated tool, but good enough if there is none).