0

I have a variable $path with a value of "/home".

The variable $path is stored in a text file like this:

$path/programs

In my script, I am getting the line from the text file and setting it to a variable $ful_path

Problem: The variable $full_path is not getting the value of $path

echo $full_path

Result:

$path/programs

When I echo $path/programs from the command line, I do get /home/programs, it's only in the script as a variable it's being treated as a string.

sticky bit
  • 35,543
  • 12
  • 29
  • 39
Moses Davidowitz
  • 982
  • 11
  • 27

1 Answers1

0

You are probably doing something like :

export path=/home
echo '$path/programs' > test-file

full_path="$(cat test-file)"
echo "$full_path"

You can substitute variables with envsubst :

export path=/home
echo '$path/programs' > test-file

full_path="$(cat test-file | envsubst)"
echo "$full_path"
Philippe
  • 14,211
  • 2
  • 16
  • 22