0

So I have a file "Directories.dat" that contains a list of directories for a script to read that runs on multiple machines. Due to this, the list of directories in the file is often defined with variables such as

#Directories.Dat
/home/$USER
$WORKDIR
$APPDIR
...etc 

However, when the script runs through the file Directories.dat , $line ends up being set to /home/$USER rather than /home/myuser

#!/bin/bash
#myscript.sh
for line in $(cat Directories.dat) 
do 
SomeCommand $line
done

Should I not use cat? Is eval the only suitable function for doing this? example SomeCommand $(eval echo $line) #DangerZone or are there other methods to read the lines within the Directories.dat file and show the variables as their stored values?

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
link
  • 1

1 Answers1

0

Moved from the question

#!/bin/bash
source bashrc.sh mysources.sh
#myscript.sh
for line in $(cat Directories.dat) 
do 
SomeCommand $(echo $line | envsubst)
done
Chris Davies
  • 116,213
  • 16
  • 160
  • 287