title: Bash substitution inside substitution
body: <p>I am learning bash, and wanted to do something very simple, here's my script:</p>
  
  <pre><code>#!/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
  </code></pre>
  
  <p>In the <code>for</code> loop I am trying to print to values entered by the user, only at the <code>echo</code>line I get the error:</p>
  
  <pre><code>${var"$i"}: bad substitution 
  </code></pre>
  
  <p>What I was expecting to happen is:</p>
  
  <ol>
  <li><code>$i</code> expands to the current value between 1 and 5 (say 1 for example)</li>
  <li><code>${var"$i"}</code> expands to ${var1} which expands to the value of var1</li>
  </ol>
  
  <p>This is not the case apparently...Could you explain to me why that is ? does bash expand everything on the line at once?</p>
  
  <p>I have also tried <code>${var${$i}}</code> and <code>$var${$i}</code> but both give the same error...why is that ?</p>