If you have a file that looks like this:
a=${env1} is a good ${env2}
b=${env3} is a good ${env4}
And you want to produce output with the variables substituted, you use the `envsubst` command, which is part of the `gettext` package. Assuming the above is in `example.txt.in`, we could run:
env1=tom env2=cat env3=jerry env4=mouse envsubst < example.txt.in
And get as output:
a=tom is a good cat
b=jerry is a good mouse
* * *
If `ensubst` isn't available, you could do something like:
#!/bin/sh
tmpfile=$(mktemp scriptXXXXXX)
trap 'rm -f $tmpfile' EXIT
cat > "$tmpfile" <
END_INSIDE
END_OUTSIDE
sh "$tmpfile"
Name the script something like `envsubst.sh`, and run it similarly to the previous example:
`env1=tom env2=cat env3=jerry env4=mouse sh envsubst.sh < example.txt.in`