Skip to content

Instantly share code, notes, and snippets.

@hell0again
Created February 19, 2015 02:25
Show Gist options
  • Save hell0again/473a65ae185045ff016d to your computer and use it in GitHub Desktop.
Save hell0again/473a65ae185045ff016d to your computer and use it in GitHub Desktop.
シェルスクリプトでテンプレートエンジン的な
I am template.
lang: ja_JP.UTF-8
key1: val1
key2: val2
key3:
key4: UNDEF
#!/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
I am template.
lang: ${LANG}
key1: ${key1}
key2: ${key2}
key3: ${key3}
key4: ${key4-UNDEF}
@hell0again
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment