bash-utils/shtpl/README.md

48 lines
874 B
Markdown
Raw Normal View History

2018-10-09 17:08:34 +02:00
# shtpl
2018-10-09 17:22:17 +02:00
> sh templating
2018-10-09 17:08:34 +02:00
## 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:
2018-10-09 17:22:17 +02:00
```
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)
```