A rather unsafe, very trusting templating engine that lets you use bash as your parser.
Based on http://serverfault.com/questions/287688/templating-with-linux-in-a-shell-script/#699377
but.sh requires only bash
wget https://raw.github.com/nealian/bash-unsafe-templates/master/but.sh && chmod +x but.sh
The current shell environment is used, and additional variables may be set in two ways:
- As with any other script, you may specify variable values on the command line (
FOO=bar ./but.sh) - Additionally, environment files may be sourced with the
-cand--configflags (and any filenames at the end of the arguments)
Templates are text files with bash expansions, and with escaped double-quotes and backslashes.
but.sh will expand the following:
$VARand${VAR}(and${ARRAY[@]}and other more complicated variable expansions)$(())arithmetic expansions- Backtick (
``) and paren-style ($()) command substitions
`may be printed in the output with\`$may be printed in the output with\$"may be printed in the output with\"\may be printed in the output unescaped in most cases- If it is to be followed immediately by a
`, a$, a", a newline, or another\, it must be escaped with\\ - All other characters will be printed normally
These follow the rules of a bash here-document
- See the bash manual
This repository includes an example template and its output. Additionally, this gist includes the template I actually initially built this for.
but.sh <template-file> [-o|--output <output-file>] [[[-c|--config] <config-file>] ...]