I am new to scripting. I am getting a bad substitution error while running this code. I want to print the values in h_1, h_2, h_3with a for loop.#/!/bin/bashh_1=12h_2=13h_3=14for ((i=1; i<=2; i++)) do  echo ${h_$i}done
how to pass a value to a variable that in a other variable
bash
You need to use indirect parameter expansion with !:tmp=h_$iecho ${!tmp}You have to make the extra tmp variable here - you can't just use a string, unfortunately. Indirect expansion works as follows:If the first character of parameter is an exclamation point (!), a level of variable indirection is introduced. Bash uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution, rather than the value of parameter itself. This is known as indirect expansion.So, above, ${!tmp} expands to the value of the variable whose name is given by the value of the variable tmp.It's also possible to use eval here, but the indirection approach is tidier.