From: | Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: psql in a bash function |
Date: | 2018-03-12 18:32:24 |
Message-ID: | 5d7d2c62-6e8a-ef53-d1d2-c48588006c48@cox.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I knew it was something simple... Thanks
On 03/12/2018 01:24 PM, Eric Raskin wrote:
> Yes, you need double quotes around $@, as in "$@".
>
> https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
>
>
>
> Sent from my Verizon, Samsung Galaxy smartphone
>
>
> -------- Original message --------
> From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
> Date: 3/12/18 2:15 PM (GMT-05:00)
> To: pgsql-general <pgsql-general(at)postgresql(dot)org>
> Subject: psql in a bash function
>
>
>
> Hi,
>
> Because I need to log into many servers, I created functions as keyboard
> shortcuts (not aliases, since I will want to embed these shortcuts in
> other functions).
>
> psqlxyz ()
> {
> echo "P1=$1";
> echo "P2=$2";
> psql -U postgres -h XYZ $@
> }
>
> This is the (simple, test) command that I want to run, which works when
> run explicitly using psql, but not my function. Any ideas why the
> function isn't properly passing the "-c" and '"select ..."' to psql?
>
> $ psql -U postgres -h XYZ -c "select oid, datname from pg_database;"
> oid | datname
> ---------+------------------------
> 1 | template1
> 11563 | template0
> 11564 | postgres
> 16404 | test1
> 3039800 | ABCD
> 319011 | EFGH
> 649861 | IJKL
> (7 rows)
>
> $ psqldba -c *'*"select oid, datname from pg_database;"*'*
> P1=*-c*
> P2=*"select oid, datname from pg_database;"*
> psql: warning: extra command-line argument "datname" ignored
> psql: warning: extra command-line argument "from" ignored
> psql: warning: extra command-line argument "pg_database;"" ignored
> psql: FATAL: database "oid," does not exist
>
> Thanks
>
> --
> Angular momentum makes the world go 'round.
--
Angular momentum makes the world go 'round.
From | Date | Subject | |
---|---|---|---|
Next Message | greigwise | 2018-03-12 18:33:52 | pglogical lag due to replication timeout |
Previous Message | Steven Roth | 2018-03-12 18:26:20 | UPSERT on a view |