Bash command line help scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.6 KiB


sh templating


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


Create a template file to be executed with shtpl:

nano someTpl.shtpl
Hello $WHO !

Make the template executable:

chmod +x someTpl.shtpl

... and execute it with some environment variables:

WHO=Doctor ./someTpl.shtpl
> Hello Doctor !

In case of many variable you can write 1 var on each line, but for bash to understand you have to escape the newlines and keep 1 space before:

VAR1=foo \
VAR2=bar \
VAR3=baz \
VAR4=aze \

To save the result simply redirect to sdtout to a file:

WHO=Doctor ./someTpl.shtpl > doctorGreetings.txt

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 !

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++))
	echo "[$i]"

Call sub templates: $(VAR_TO_PASS=$SOME_VAR ./myOtherTemplate.shtpl)
ENV_VAR=foo \
TOTO=42 \
SOME_VAR=aze \


Simple variable: foo , and with brackets: 42cm²

Sub commands: ok

Prompt user input in place: your input

Loops: [0][1][2][3][4][5][6][7][8][9][10]

Call sub templates: what the template returns with "aze"