How do I use a for loop to define a variable, and its value, and be able to evaluate it?
I can't figure out the evaluation part, but using the for loop to define the variable and its value seems to work. Specifically,
for i in {1..4}
do
export my${i}var="./path${i}_tofile"
# or
# export my${i}var=./path${i}_tofile
# or
# eval "my${i}var=\"./path${i}_tofile\""
echo $[my${i}var]
done
The echo
does not evaluate correctly, but the shell does correctly create the variable and the value.
echo $my1var
returns
./path1_tofile
But I need to evaluate the variables using the $i
as part of their names.