[Top][All Lists]

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

Re: Reading mysql data stream into array

From: Dirk
Subject: Re: Reading mysql data stream into array
Date: Fri, 06 May 2011 18:22:25 +0200
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv: Gecko/20100915 Thunderbird/3.1.4

 Am 06.05.11 18:12, schrieb DJ Mills:
On Fri, May 6, 2011 at 12:07 PM, Dirk<address@hidden>  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

I really tried finding out myself, but I am stuck, so please can someone
point me to what I do wrong?

Thanks in advance,


'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?
I should have expected it to be something stupid like that. Thank you!

I was fooled by "echo $SHELL" returning "/bin/bash", but when I manually call "/bin/bash" before running the above command (it is not a script yet), it works.

What the heck is going on here ... (!x****mpf)

Thanks for your fast help!


reply via email to

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