On Fri, May 6, 2011 at 12:07 PM, Dirk <dirk.sch...@kinzesberg.de> wrote:
> Hi folks, > > I am going nuts trying to read the output of a mysql select statement into > an array. I have consulted bashfaq and other sources and tried various > approaches, but every jump was somewhat short, it seems. > > This is what I tried (bash is 3.2.xx, I tried on MacOS X and Debian Lenny): > > while read -r; do messag[i++]=$REPLY; done < <(mysql select statement) > # this is from BashFAQ Nr. 5 - is this possible with bash 3.2.x at all? > this got me complains about unexpected "<" and such > > $(mysql select command) | while read line; do messag+=($line); done > # this basically works, but counting up the array index does not > I also tried > ... do messag[i++]=($line) > # -bash: messag[i++]: cannot assign list to > array member (????) > ... do messag[i]=$line && i=$(($i+1)) > ... do messag[$i]=$line && i=$(($i+1)) > > It never results in every line of the mysql output becoming an array > element. > > I really tried finding out myself, but I am stuck, so please can someone > point me to what I do wrong? > > Thanks in advance, > > Dirk > > 'this got me complaints about unexpected "<" and such' You generally want to give specific errors. It almost sounds like you may be using sh, and not bash Is the first line of your script #!/bin/sh, or #!/bin/bash? while read -r; do messag+=("$REPLY"); done < <(mysql ...) should work fine. As should the first example you gave.