On Thu, May 21, 2015 at 06:52:08PM +0200, Richard Taubo wrote:
> Creating a simple array, I am just wondering why the second printf line
> does not print any results from the array at all.
> #!/bin/bash
> MyData="One,two,three"
> declare -i q
> OIFS=$IFS
> IFS=$','
> for myColumn in $MyData; do
> MyArray[q++]="${myColumn#*}"
> printf "%s\n" "$q: ${MyArray[q-1]}"
> printf "%s\n" "$q: ${MyArray[q]}"
> done
> IFS=$OIFS
After the first MyArray[q++] line, you have an array with one element
(element 0) and q is set to 1. So when you try to reference MyArray[1]
there's nothing there.
The same thing occurs each time through the loop.