I have a small program which needs to pass variable dynamically to form the name of a second variable whose value wil be passed on to a third variable.
***************** Program Start ******************
LOC1=/loc1
PAT1IN=/loc2
PAT2IN=/loc3
if [ -f $LOC1/* ]; then
for fpattern in `cat $script/filepattern.txt`
do
for ffilename in `find $LOC1/ -type f`
do
filename=`echo $ffilename | cut -d "/" -f 3`
file=`echo $filename | cut -d "_" -f 1`
case "$file" in
$fpattern)
INLOC=${${file}IN}
echo $INLOC
echo $filename
;;
esac
done
done
else
echo "Exiting Job as no files present."
exit
fi
***************** Program End ******************
List of files present in the /loc1 are as below
/loc1/PAT1_test.txt
/loc1/PAT2_test1.txt
content of filepattern.txt are as below
PAT1
PAT2
when i execute the program, i keep getting this error
INLOC=${${file}IN}: bad substitution
Please let me know if i am doing something wrong. or is there an alternate way to achieve this without having to use to much variables.
expected output is:
/loc2
PAT1_test.txt
/loc3
PAT2_test1.txt