title: How to use variables in a bash for loop
body: <p>How does one use a variable in a bash for loop?
  If I just use a standard for loop, it does what I expect</p>
  
  <pre><code>for i in {0..3}
  do
     echo "do some stuff $i"
  done
  </code></pre>
  
  <p>This works fine.  It loops thru 4 times, 0 to 3 inclusive, printing my message and putting the count at the end.</p>
  
  <pre><code>do some stuff 0
  do some stuff 1
  do some stuff 2
  do some stuff 3
  </code></pre>
  
  <p>When I try the same thing with the following for loop, it seems to equal a string, which is not what i want.</p>
  
  <pre><code>length=3
  for i in {0..$length}
  do
     echo "do something right $i"
  done
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>do something right {0..3}
  </code></pre>
  
  <p>I've tried </p>
  
  <pre><code>for i in {0.."$length"} and for i in {0..${length}} (both output was {0..3})
  </code></pre>
  
  <p>and</p>
  
  <pre><code>for i in {0..'$length'} (output was {0..$length})
  </code></pre>
  
  <p>and they both don't do what I need.  Hopefully someone can help me.  Thanks in advance for any bash expert's help with for loops.</p>