Skip to content

Instantly share code, notes, and snippets.

@progrium
Created April 2, 2015 23:17
Show Gist options
  • Save progrium/8b20dd6314f3b164244a to your computer and use it in GitHub Desktop.
Save progrium/8b20dd6314f3b164244a to your computer and use it in GitHub Desktop.
render-template() {
declare filename="$1"; shift
local script k v
for var in "$@"; do
IFS='=' read k v <<< "$var"
script="s/\$\$$k/${var##${k}=}/;$script"
done
cat "$filename" | sed "$script"
}
# usage: render-template /path/to/template foo=bar baz=qux
# replaces $$foo and $$baz in template to values bar and qux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment