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?
envsubst
- see for example how do I get my code to use the value of the $HOME variable? – steeldriver Nov 18 '20 at 20:51