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
1

1 Answer 1

1

Sure, use envsubst

It's part of GNU get text

envsubst < source > destination

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.