I am trying very simple thing using shell script on BASH shell. I am trying to get keyids of all Users into an array in a shell script. I will later loop them for further processing.
I wrote very simple code. But I am stuck while converting a space separated QUERY_RESULTS string into an array.
I tried various options e.g. set -A , read -a, array=( $ QUERY_RESULTS } ) etc.
Nothing is working for me. Every-thing I try, gives me some error.
For e.g.
set -Agives meillegal option -A.read -aalso gives meillegal option -a.array=( $ QUERY_RESULTS } );gives me( unexpected.
Below is my code. Please help me here.
#IFS="";
echo "Get list of Active Users from Table ";
QUERY_RESULTS=$( mysql -u username password -e "SELECT keyid from users where isActive = 1" );
echo $QUERY_RESULTS;
#eval `read -a arr <<$QUERY_RESULTS`;
#array=( $ QUERY_RESULTS } );
echo $array;