Re: multiple sql results to shell

From: Randy Strauss <rstr(at)stanford(dot)edu>
To: "pgsqladmin(at)geoff(dot)dj" <pgsqladmin(at)geoff(dot)dj>, "mlybarger(at)gmail(dot)com" <mlybarger(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: multiple sql results to shell
Date: 2017-10-23 22:14:28
Message-ID: 49FB3234-4E2C-474E-ABA3-E2C9196E59AE@stanford.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

On Oct 23, 2017, at 08:37, pgsql-general-owner(at)postgresql(dot)org<mailto:pgsql-general-owner(at)postgresql(dot)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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Geoff Winkless 2017-10-24 09:58:18 Re: multiple sql results to shell
Previous Message Geoff Winkless 2017-10-23 10:17:42 Re: Processing very large TEXT columns (300MB+) using C/libpq

Browse pgsql-general by date

  From Date Subject
Next Message Paul Jungwirth 2017-10-23 22:17:40 Two versions of an extension in the same cluster?
Previous Message John R Pierce 2017-10-23 21:42:39 Re: using conda environment for plpython3u?