Sunday, 15 September 2013

mysql - Bash script and rows -



mysql - Bash script and rows -

my problem rows mysql_query. need:

record 0: 2,text text,3.23

but have:

record 0: 2 record 1: text record 2: record 3: text record 4: 3.23

please help me.

results=($(mysql --user root -proot test -bse "select id,name object")); cnt=${#results[@]} (( i=0 ; i<${cnt} ; i++ )) echo "record no. $i: ${results[$i]}" fielda=${results[0]}; fieldb=${results[1]}; done

the problem storing output of mysql array. now, if mysql returns multiple records won't know when record ends , next 1 starts because array contain "flattened" info e.g. ( record1_fielda record1_fieldb record2_fielda record2_fieldb ... )

instead, utilize while loop iterate on records this:

i=0 while read fielda fieldb echo "record $(( i++ )): fielda: $fielda fieldb: $fieldb" done < <(mysql --user root -proot test -bse "select id,name object")

mysql arrays bash

No comments:

Post a Comment