title: Accessing array index variable from bash shell script loop?
body: <p>I want to access the array index variable while looping thru an array in my bash shell script.</p>
  myscript.sh
  <pre><code>#!/bin/bash
  A=('foo' 'bar' 'baz' 'bat')
  for i in ${A[*]}; do
    echo $i
  done
  </code></pre>
  Actual result
  <pre><code>foo
  bar
  baz
  bat
  </code></pre>
  Desired result
  <pre><code>0
  1
  2
  3
  </code></pre>
  <p>How do I alter my script to achieve this?</p>