Basic templating

Sometimes you need a simple templating in bash without any logic.

You can use sed or even awk but for simple substitute of variable in a file envsubst is the best option. Placeholders are usual bash variables like $MY_VAR or ${MY_VAR} (I prefer the latter as it’s simple to read).

envsubst unable to replace vars inline, thus you can redirect output. If input and output are the same file you’ll need smth like sponge tool that will buffer the input and only when it gets all the input it’ll write it in the file.

apk add gettext moreutils
apt install gettext-base gettext moreutils -y
yum install epel-release -y && yum install gettext moreutils -y
envsubst < ${item} | sponge ${item}