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: Richard Taubo
Subject: Re: [Help-bash] Printing from Array
Date: Thu, 21 May 2015 19:52:09 +0200

Okay, thanks for the hint! :-)

Richard Taubo

> May 21, 2015 kl. 7:28 PM skrev Dennis Williamson <address@hidden>:
> 
> Perhaps you want ++q instead of q++, but note that will skip MyArray[0] 
> (meaning it will be null/unset).
> 
> On Thu, May 21, 2015 at 12:02 PM, Greg Wooledge <address@hidden 
> <mailto:address@hidden>> wrote:
> 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.
> 
> 
> 
> 
> -- 
> Visit serverfault.com <http://serverfault.com/> to get your system 
> administration questions answered.



reply via email to

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