0

I have printable text in a file (header.txt):

*******************
* $string
*******************

and I have the script (generate.sh):

prn_header () {
   string=$1
   echo $(<header.txt)
}

prn_header I_want_this_text_for_the_header

and the output is exactly the same like the header.txt.

My problem is: how can I get the template from a file, but substitute the needed variable in it before printing?

In real, I have many text pieces in files, and the result builded from them.

3
  • See mywiki.wooledge.org/TemplateFiles Commented Feb 8, 2016 at 16:07
  • By the way -- do you trust your templates to not be malicious? That is to say, is it a problem if a template containing $(rm -rf ~) were to have that code executed on evaluation? Commented Feb 8, 2016 at 16:07
  • Okay, thanks, I found it. :) Commented Feb 9, 2016 at 9:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.