Re: [GENERAL] multiple sql results to shell - Mailing list pgsql-general

From Randy Strauss
Subject Re: [GENERAL] multiple sql results to shell
Date
Msg-id 49FB3234-4E2C-474E-ABA3-E2C9196E59AE@stanford.edu
Whole thread Raw
In response to [GENERAL] multiple sql results to shell  (Mark Lybarger <mlybarger@gmail.com>)
List pgsql-general
On Oct 23, 2017, at 08:37, pgsql-general-owner@postgresql.org wrote:

psql ..... | while read a; do
#    some code
done

The only problem I find with this is that you can't pass variables out
of the while loop,

To get input from a file w/o a sub-shell,
you can put the input at the end of the loop:

====
#!/bin/sh                                                                                                                                                                                                                                     

cat > file <<EOF                                                                                                                                                                                                                              
ab                                                                                                                                                                                                                                            
cd                                                                                                                                                                                                                                            
ef                                                                                                                                                                                                                                            
EOF                                                                                                                                                                                                                                           
while read a; do
    b="$b $a"
    echo $b
done < file
====
-Randy

pgsql-general by date:

Previous
From: John R Pierce
Date:
Subject: Re: [GENERAL] using conda environment for plpython3u?
Next
From: Paul Jungwirth
Date:
Subject: [GENERAL] Two versions of an extension in the same cluster?