Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md

README.md

One-liners

I assume that you've installed FakeTpl some how as was described here To try all these examples, let's 'source' it:

source faketpl

And now, everything is ready to go ;)

default values

$ echo '[${MYVAR:-default}]' | faketpl
[default]
$ MYVAR=something; echo '[${MYVAR:-default}]' | faketpl
[something]

if some variable wasn't set, then raise an error

To raise an error we need set -u

$ (set -u; faketpl <<< '${ASD}' 2>/dev/null) || echo "Error: ASD variable has to be set"
Error: ASD variable has to be set

or

$ (set -u; echo '${ASD}' | faketpl 2>/dev/null) || echo "Error: ASD variable has to be set"
Error: ASD variable has to be set

or

$ (set -u; faketpl < some.conf.ftpl > some.conf 2> /dev/null) || echo "Error: ASD variable has to be set"
Error: ASD variable has to be set

how to use arrays?

To use arrays we need a shell that supports them, like BASH. Don't forget to declare an array as declare -a VAR first, especially if it's an associative array as declare -A VAR.

$ declare -A FRIENDS

$ FRIENDS=([Max]="Krakow" [Alex]="Rome")

$ faketpl << -=END=-
> I came from $(hostname)
> $(IFS=' '; for name in $(tr ' ' '\n' <<< ${!FRIENDS[@]} | sort -n | tr '\n' ' '); do echo "${name} came from ${FRIENDS[${name}]}"; done)
> -=END=-

I came from marche
Alex came from Rome
Max came from Krakow

go through all sub-directories and render all templates

Let's assume we have a path tree like

$ tree ftpls
ftpls
├── 1
│   ├── 2
│   │   └── index.html.ftpl
│   └── index.html.ftpl
└── index.html.ftpl

to get real files just run

source faketpl
find ftpls/ -name "*.ftpl" | \
while read fn; do \
    faketpl < ${fn} > ${fn%%.ftpl}; \
done
You can’t perform that action at this time.