Store mysql result in a bash array variable -


i trying store mysql result global bash array variable don't know how it.

should save mysql command result in file , read file line line in for loop other treatment?

example:

#database, table uses  user password pierre aaa paul bbb 

command:

$results = $( mysql –uroot –ppwd –se  « select * users ); 

i want results contains 2 rows.

mapfile containing whole table 1 bash variable

you try this:

mapfile result < <(mysql –uroot –ppwd –se  "select * users;") 

than

echo ${result[0]%$'\t'*} echo ${result[0]#*$'\t'} 

or

for row in "${result[@]}";do     echo name:  ${row%$'\t'*}  pass: ${row#*$'\t'} done 

nota work fine while there 2 fields row. more possible become tricky

read reading table row row

while ifs=$'\t' read name pass ;do     echo name:$name pass:$pass   done  < <(mysql -uroot –ppwd –se  "select * users;") 

read , loop hold whole table many variables:

i=0 while ifs=$'\t' read name[i] pass[i++];do     :;done  < <(mysql -uroot –ppwd –se  "select * users;")  echo ${name[0]} ${pass[0]} echo ${name[1]} ${pass[1]} 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -