I have written this simple function to read a template file, replace a few values in it, and then save it to an actual file.
However, I'd like to keep the indents that are in the template file. As of now, its just producing a new file without indents at all.
function create_vhost_conf_from_template {
while IFS='' read -r line || [[ -n "$line" ]]; do
line=${line/\[SERVERNAME\]/$server_name}
line=${line/\[VHOSTROOT\]/\/var\/www\/vhosts\/$vhost\/httpdocs}
echo $line | tee -a /etc/nginx/sites-enabled/$vhost.conf
done < "/root/templates/$1"
}