bash-utils/shtpl
dig c21567f507 Mettre à jour 'shtpl/README.md' 2018-10-09 17:22:17 +02:00
..
README.md Mettre à jour 'shtpl/README.md' 2018-10-09 17:22:17 +02:00
shtpl Added shtpl utility 2018-10-09 16:54:38 +02:00
test.sh shtpl: rename test file 2018-10-09 17:02:44 +02:00
test.shtpl shtpl: rename test file 2018-10-09 17:02:44 +02:00

README.md

shtpl

sh templating

Install

Put the shtpl script somewhere meant for executable scripts like ~/bin/shtpl. Make it executable: chmod +x shtpl.

Usage

Create a template file to be executed with shtpl:

nano someTpl.shtpl
#!/path/to/shtpl
Hello $WHO !
chmod +x someTpl.shtpl
WHO=Doctor someTpl.shtpl
> Hello Doctor !

Templating syntax

shtpl uses a hack to turn you file into a call of echo "<your file here>", so it is simple, all what your system is able to understand as substitution is valid !

#!/path/to/shtpl
Simple variable: $ENV_VAR , and with brackets: ${TOTO}cm²

Sub commands: $(echo ok)

Prompt user input in place: $(read -r -p Type\ some\ text\ : v;echo $v)

Loops: $(
for ((i=0 ; $MAX_LOOP - $i ; i++))
    do
	echo $i
done
)

Call sub templates: $(VAR_TO_PASS=$SOME_VAR ./myOtherTemplate.shtpl)