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
  • 36,626
  • 12
  • 31
  • 42
Moses Davidowitz
  • 982
  • 11
  • 28

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
  • 20,025
  • 2
  • 23
  • 32