Store variables in Bash from a result in postgreSQL

0

I have a Bash script on Linux:

psql postgresql://postgres:****@****/**** --quiet --no-align --field-separator ' ' -t -c "SELECT * FROM *" | while read -a Datos_Consulta ; do

Where I store the data of the variables as follows:

DATO1=${Datos_Consulta[0]}
DATO2=${Datos_Consulta[1]}
DATO3=${Datos_Consulta[2]}

and then I show it like this:

echo "DATO 1: $DATO1"
done

The cycle is completed once you have gone through all the rows.

Up to here everything is perfect, the problem is when one of the data has spaces, for example if I have:

id: 2323
fecha: 29/06/2018
nombre: Juan Perez

I take the id as [0], the date as [1] but the name as [2] and [3] for the space ... the problem I have is that I do not know the fixed size or the amount of space that there are in certain fields (some are descriptions)

Is there a way I can take it complete with spaces and everything?

    
asked by JuanManuel245 29.06.2018 в 16:55
source

0 answers