From c2e47f996cb4431322283d0250d544c8482299cd Mon Sep 17 00:00:00 2001 From: dig Date: Tue, 9 Oct 2018 17:36:06 +0200 Subject: [PATCH] =?UTF-8?q?Mettre=20=C3=A0=20jour=20'shtpl/README.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shtpl/README.md | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/shtpl/README.md b/shtpl/README.md index 661815e..23f758f 100644 --- a/shtpl/README.md +++ b/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 ""`, 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" ``` \ No newline at end of file