Last active
June 13, 2016 20:35
-
-
Save olegch/58f323be18dfc8426929d70d60d70461 to your computer and use it in GitHub Desktop.
Simple template engine with bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello: X=$X | |
Hello: X=$X''' | |
Hello: X="$X" | |
Hello: X=$X "kjh | |
kjd" | |
$(date) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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