Skip to content

Instantly share code, notes, and snippets.

@olegch
Last active June 13, 2016 20:35
Show Gist options
  • Save olegch/58f323be18dfc8426929d70d60d70461 to your computer and use it in GitHub Desktop.
Save olegch/58f323be18dfc8426929d70d60d70461 to your computer and use it in GitHub Desktop.
Simple template engine with bash
Hello: X=$X
Hello: X=$X'''
Hello: X="$X"
Hello: X=$X "kjh
kjd"
$(date)
#!/bin/bash
# first let's import gen-template function
source gen-template.sh
# set variables used in the template
X=abc
# now let's generate text from the template - it will be printed to stdout
gen-template example-template
# ... or we can save it to a file
gen-template example-template > file
#!/bin/bash
function gen-template() {
local tpl_file="$1"
local tpl_body="$(cat $tpl_file)"
eval "$(cat <<nNEZzh14FVSdj9PkY8feFaqoFyCZRdMx
cat <<Yd3ykiiIaWDrgbqLJzzSVKw455ZzrpSP
$tpl_body
Yd3ykiiIaWDrgbqLJzzSVKw455ZzrpSP
nNEZzh14FVSdj9PkY8feFaqoFyCZRdMx
)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment