How could I separate the values obtained in an array according to the search string? Example: I use this code:
#!/bin/bash
#Ref = https://www.linuxquestions.org/questions/programming-9/bash-to-loop-thorouh-mysql-select-array-882907/#post5798608#
#
DBUSER="user"
DBNAME="pass"
results=($(mysql --user ${DBUSER} ${DBNAME} -Bse "select phonenumber, userattr from usersSis WHERE sendMSG = '0';"))
cnt=${#results[@]}
for (( i=0; i<${cnt}; i++ ))
do
echo "Total. $i: ${results[$i]} "
# NumPhone1=${results[0]};
# CodPhone1=${results[1]};
# NumPhone2=${results[2]};
# CodPhone2=${results[3]};
echo "---------------------------------------------------------------------------------------------------"
done
The result is :
Total. 0: 1223121219
---------------------------------------------------------------------------------------------------
Total. 1: 667
---------------------------------------------------------------------------------------------------
Total. 2: 3223121219
---------------------------------------------------------------------------------------------------
Total. 3: 2005
---------------------------------------------------------------------------------------------------
Total. 4: 5223121219
---------------------------------------------------------------------------------------------------
Total. 5: 545454
---------------------------------------------------------------------------------------------------
Could they look like this? REF: Loop through an array of strings in Bash? Creating an associative array. A dictionary:
declare -A continent
continent[Vietnam]=Asia
continent[France]=Europe
continent[Argentina]=America
for item in "${!continent[@]}";
do
printf "$item is in ${continent[$item]} \n"
done
Output:
Argentina is in America
Vietnam is in Asia
France is in Europe
var1 = 1223121219 and var2 = 667 var3 = ... and var4 = ... ... ...