Created
February 19, 2015 02:25
-
-
Save hell0again/473a65ae185045ff016d to your computer and use it in GitHub Desktop.
シェルスクリプトでテンプレートエンジン的な
This file contains hidden or 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
I am template. | |
lang: ja_JP.UTF-8 | |
key1: val1 | |
key2: val2 | |
key3: | |
key4: UNDEF |
This file contains hidden or 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/sh | |
function template() { | |
t=$(cat $1) | |
compiled=$(cat <<EOFF | |
cat <<EOF | |
${t} | |
EOF | |
EOFF | |
) | |
eval "${compiled}" | |
} | |
key1="val1" key2="val2" template tmpl | |
key1="foo" key2="bar" template tmpl |
This file contains hidden or 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
I am template. | |
lang: ${LANG} | |
key1: ${key1} | |
key2: ${key2} | |
key3: ${key3} | |
key4: ${key4-UNDEF} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.gnu.org/software/m4/