0

This question already has an answer here:

I have a file with variables in it like below, however I want to use this file as a template and replace the variables with its actual value.

Is there a way to read the file contents and evaluate the variables?

#my script
template=$(cat script.template)
MY_VAR="my_data"
echo $template

The above script should read the below file, and replace MY_VAR with the string my_data

# script.template
export MY_VAR=${MY_VAR}

Is there a way to accomplish this with bash?

# expected output
export MY_VAR=my data

marked as duplicate by ilkkachu, Anthon, roaima, Kusalananda, Stephen Harris Aug 11 '16 at 19:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Sure, use envsubst

It's part of GNU get text

envsubst < source > destination

Not the answer you're looking for? Browse other questions tagged or ask your own question.