I'm trying to make a nested variable prompt for loop in Bash. However, I get the error bad substitution.
#! /bin/bash
echo "how many sources?"
read NumSour
for (( i=1; i<=$NumSour; i++ ))
do
echo "what is the wavelength of source" ${i}"?"
read Wave${i}
for j in Wave${i}
do
echo ${Wave${i}}
done
done
I want to prompt how many variables, then assign each of those variables with a value. Then print the variables’ values.
Echoing ${j} gives Wave1, Wave2, etc. not the values of the variables.
I tried switching to format of the second for loop with the same as the first for loop, but it iterates over the values of the variables.
for (( i=1; i<=$NumSour; i++ ))
do
echo "what is the wavelength of source" ${i}"?"
read Wave${i}
for (( j=Wave1; j<=Wave${i}; j++ ))
do
echo ${j}
done
done
Say Wave1 is 1 and Wave2 is 4, it echos 1, 2, 3, and 4. I need it to just echo 1 and 4.