pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron Johnson <ron.l.johnson@cox.net>
To: pgsql-general <pgsql-general@postgresql.org>
Subject: psql in a bash function
Date: Mon, 12 Mar 2018 13:14:26 -0500
Message-ID: <32feadd1-7601-6a39-9fb8-bd1d3544f2e2@cox.net> (raw)

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.

view thread (4+ messages)  latest in thread

Message-ID: <32feadd1-7601-6a39-9fb8-bd1d3544f2e2@cox.net>
Permalink:  ../32feadd1-7601-6a39-9fb8-bd1d3544f2e2@cox.net/
Also on:    postgresql.org/message-id/32feadd1-7601-6a39-9fb8-bd1d3544f2e2@cox.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ron.l.johnson@cox.net
  Subject: Re: psql in a bash function
  In-Reply-To: <32feadd1-7601-6a39-9fb8-bd1d3544f2e2@cox.net>
  References: <32feadd1-7601-6a39-9fb8-bd1d3544f2e2@cox.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox