Simple bash example to store the output of a MySQL query in an array:
dbquery=$(mysql -u username -p password -e "use table; select field from table;")
array=( $( for i in $dbquery ; do echo $i ; done ) )
you can check the contents of your new array with:
echo ${array[@]}
Now that you have a nice array, you can do things like this:
for i in ${array[@]}
do echo $i
or, more sophisticated:
cnt=${#array[@]}
for (( i=0 ; i<cnt ; i++ ))
do echo "Record No. $i: ${array[$i]}"
done
simple, but effective !
one simple way is
dbquery=($(mysql -u username -p password -e "use table; select field from table;"))
now $dbquery is an array with the query values
Posted by: Jesus Guifarro | August 27, 2010 at 04:17 PM
thank you very much
Posted by: bocian85 | August 22, 2011 at 01:45 PM
Thankyou, very simple and work!
Posted by: Bui | March 14, 2013 at 08:40 AM