Last Updated: June 09, 2019
·
4.486K
· gpakosz

Bash/Sh as a template engine

Sample template file:

Username: ${user}

Usage:

#!/bin/sh

# render a template configuration file
# preserve formatting
# expand variables
render_template() {
  eval "echo \"$(cat $1)\""
}

user="Gregory"
render_template /path/to/template.txt > path/to/configuration_file

Will replace ${user} with "Gregory" in the template, keeping formatting

1 Response
Add your response

nice. here is my solution (it parses only lines beginning with $)

over 1 year ago ·