Browse Source

Mettre à jour 'shtpl/README.md'

master
dig 3 years ago
parent
commit
c2e47f996c
  1. 44
      shtpl/README.md

44
shtpl/README.md

@ -17,14 +17,35 @@ nano someTpl.shtpl
#!/path/to/shtpl
Hello $WHO !
```
Make the template executable:
```
chmod +x someTpl.shtpl
WHO=Doctor 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 \
./someTpl.shtpl
```
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 !
@ -40,9 +61,28 @@ 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
echo "[$i]"
done
)
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"
```
Loading…
Cancel
Save