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
Written by Gregory Pakosz
Related protips
1 Response
nice. here is my solution (it parses only lines beginning with $)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#