I have these variables
a1=0.017
a2=0.2
a3=10.7
a4=20.9
a5=35.4
for ((x=1; x<=5; x++))
do
for i in a${x}
do
echo "Welcome $i times"
done
done
The output must be:
"Welcome 0.017 times"
"Welcome 0.2 times"
"Welcome 10.7 times"
"Welcome 20.9 times"
"Welcome 35.4 times"
But my output now is
Welcome a1 times
Welcome a2 times
Welcome a3 times
Welcome a4 times
Welcome a5 times
How cam I print a1 as $a1 in the way to have "10" ?
Otherwise I have to do this:
for i in $a1 $a2 $a3 $a4 $a5
do
echo "Welcome $i times"
done
The problem is that I have more than 100 "a" variables and I can not use the last option above
Are good also new suggestion outside of "loops"
Many thanks
a
array? E.g. asa[0]=10.1; a[1]=20.5
etc... And then loop withfor value in "${a[@]}"; do ...; done
.echo "Welcome ${!i} times"
- see for example Bash: Echo a variable whose name is the value of another variable