[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Printing from Array
From: |
Richard Taubo |
Subject: |
Re: [Help-bash] Printing from Array |
Date: |
Thu, 21 May 2015 19:50:03 +0200 |
> May 21, 2015 kl. 7:02 PM skrev Greg Wooledge <address@hidden>:
>
> 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.
That makes sense — well, that was akward.
Don’t know how I could overlook that . . . :-)
Thanks!
Richard Taubo