Mettre à jour 'shtpl/README.md'

This commit is contained in:
dig 2018-10-09 17:36:06 +02:00
parent c21567f507
commit c2e47f996c
1 changed files with 42 additions and 2 deletions

View File

@ -17,14 +17,35 @@ nano someTpl.shtpl
#!/path/to/shtpl #!/path/to/shtpl
Hello $WHO ! Hello $WHO !
``` ```
Make the template executable:
``` ```
chmod +x someTpl.shtpl chmod +x someTpl.shtpl
WHO=Doctor someTpl.shtpl ```
... and execute it with some environment variables:
```
WHO=Doctor ./someTpl.shtpl
``` ```
``` ```
> Hello Doctor ! > 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 \
./someTpl.shtpl
```
To save the result simply redirect to sdtout to a file:
```
WHO=Doctor ./someTpl.shtpl > doctorGreetings.txt
```
## Templating syntax ## 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 ! 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 !
@ -40,9 +61,28 @@ Prompt user input in place: $(read -r -p Type\ some\ text\ : v;echo $v)
Loops: $( Loops: $(
for ((i=0 ; $MAX_LOOP - $i ; i++)) for ((i=0 ; $MAX_LOOP - $i ; i++))
do do
echo $i echo "[$i]"
done done
) )
Call sub templates: $(VAR_TO_PASS=$SOME_VAR ./myOtherTemplate.shtpl) Call sub templates: $(VAR_TO_PASS=$SOME_VAR ./myOtherTemplate.shtpl)
```
```
ENV_VAR=foo \
TOTO=42 \
MAX_LOOP=10 \
SOME_VAR=aze \
./someTpl.shtpl
```
Returns:
```
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"
``` ```