Home > database >  variables are not interpreted when I use the "cat" command to put the contents of a text f
variables are not interpreted when I use the "cat" command to put the contents of a text f

Time:10-22

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

CodePudding user response:

You could use envsubst for this:

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