fhjmma
Last Updated: February 25, 2016
·
2.341K
· gpakosz
Snoopy

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

Say Thanks
Respond

1 Response
Add your response

5967
Photo on 08.01.2013 at 04.15

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

over 1 year ago ·
Filed Under