We have the following code
filename=`head -1 $filelist`
if [ ! -f $filename ]
then
touch $filename
fi
filelist contains the below items.
${HOME}/file1
${TEST_DIR}/file2
.
.
The output of the script described above is
${HOME} not found
The $ variables given inside the file list are not getting resolved.
Is it that the variables are not available as the script runs in a shell or something like that?
Use eval in front of touch. Existence of files is tested with -e not -f if that is what you want to do. And make sure $filelist is defined somewhere cause I could not see it.
Thanks a lot! Using eval in front of touch worked.
Can you please explain the use of eval in this context?
Echoing $filename should show you just the path without substitution of $HOME.
Era has a good description here:
http://www.unix.com/shell-programming-scripting/66063-eval-shell-scripting.html
The forum has a superb search function