I am learning bash, and wanted to do something very simple, here's my script:
#!/bin/bash
#read-multiple: reads multiple values from keyboard
echo -n "Enter one or more values:"
read var1 var2 var3 var4 var5
for i in {1..5}
do
echo var$i= ${var"$i"}
done
In the for loop I am trying to print to values entered by the user, only at the echoline I get the error:
${var"$i"}: bad substitution
What I was expecting to happen is:
$iexpands to the current value between 1 and 5 (say 1 for example)${var"$i"}expands to ${var1} which expands to the value of var1
This is not the case apparently...Could you explain to me why that is ? does bash expand everything on the line at once?
I have also tried ${var${$i}} and $var${$i} but both give the same error...why is that ?