variables are not interpreted when I use the "cat" command to put the contents of a text file into a variable

Viewed 181

I need some help please, I have a script (script.sh) that content:

#!/bin/bash

export name='toto'
file='file.txt'
content=$(cat "file.txt")
echo "$content"

file.txt content some text : I am $name

now when I run my script (script.sh) the variable $name is not interpreted and I got a result like this : I am $name And I want to have a result like : I am toto

1 Answers

You could use envsubst for this:

content=$(envsubst < "file.txt")
Related