To me this is the easiest and most powerful solution, you can even include other templates using the command eval echo "$(<template.txt)
:
Example with nested template
- create the template files, the variables are in regular bash syntax
${VARIABLE_NAME}
or$VARIABLE_NAME
you have to escape special characters with
\
in your templates otherwhise they will be interpreted byeval
.
template.txt
Hello ${name}!
eval echo $(<nested-template.txt)
nested-template.txt
Nice to have you here ${name} :\)
- create source file
template.source
declare name=royman
- parse the template
source template.source && eval echo "$(<template.txt)"
- the output
Hello royman!
Nice to have you here royman :)