help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Printing from Array


From: Greg Wooledge
Subject: Re: [Help-bash] Printing from Array
Date: Thu, 21 May 2015 13:02:36 -0400
User-agent: Mutt/1.4.2.3i

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]