Artificial intelligent assistant

How to get the psql table records in shell script? I have postgresql, in that I have a table with 10 records, I want the 10 records in 10 local variables shell script. I tried with following way, but it will store all the records in list123[0] variable not on list123[1]...list123[9]. declare -a list123 list123=( "$(psql -t -h 10.100.0.1 -U prasad statistics -c "select command from jobhandler.config_info where conf_name like '%stager%'")" ) I want each record in corresponding list123[0-9].

I'm not certain I'm answering your question. Do you want an array of 10 strings as a local variable, or 10 shell variables, each containing a string?

The latter requires a weird trick:


#!/bin/bash

COUNTER=1
eval $(psql -t -h 10.100.0.1 -U prasad statistics -c "select command from jobhandler.config_info where conf_name like '%stager%'" |
while read VAR
do
echo "list123$COUNTER='$VAR'"
((COUNTER = COUNTER + 1))
done)

echo list1231="$list1231"
echo list1232="$list1232"


This variant ends up setting shell variables named "list1231", "list1232", "list1233" ..., it does not set different elements of an array shell variable named "list123"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 0da3931fad65e5726abfcbbff1ddd92f