I am attempting to write a bash script that list the tables in my local postgres db
while read line
do
myarray+=("$line")
## debug
echo $line
done < <(psql -h ... -U ... -t -c "select distinct table_name from information_schema.columns where table_schema='myschema' ;")
I have created 36 tables but the above code outputs a 37th line that is completely blank. I checked the number of elements like so echo ${#myarray[@]} ; 37 elements.
If I run the query select distinct table_name from information_schema.columns where table_schema='myschema' ;, I get 36 records back.
I am using the process substitution approach in the while loop as it seems faster but I think the error comes from there. Any ideas?
myarray=($(psql ...))?psql? Does it have two newlines at the end or maybe \r\n? Can you post the output ofpsql ... | hd(hex dump)?[[ "$line" =~ ^[[:space:]]*$ ]] && continueat the top of the loop.psql -c "copy (<your query>) to stdout;"