0

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
Aage Torleif
  • 113
  • 5

1 Answers1

1

Sure, use envsubst

It's part of GNU get text

envsubst < source > destination