Performs the application of given key/value pairs to a source template, with generated results written to an output file.
Functions applyTemplate
accepts three arguments:
- Source template file.
- Target output file generated.
- List of key/value pairs as an array.
With the given source template:
Hello, %%COMPUTER%%. Do you read me, %%COMPUTER%%?
Affirmative, %%SPACE_MAN%%. I read you.
Open the pod bay doors, %%COMPUTER%%.
I'm sorry, %%SPACE_MAN%%. I'm afraid I can't do that.
And by calling applyTemplate
like so:
applyList=(
"COMPUTER=HAL" \
"SPACE_MAN=Dave"
)
applyTemplate \
"./template.txt" \
"./output.txt" \
applyList
We end up with a result in output.txt
of:
Hello, HAL. Do you read me, HAL?
Affirmative, Dave. I read you.
Open the pod bay doors, HAL.
I'm sorry, Dave. I'm afraid I can't do that.