psql in a bash function

Ron Johnson <ron.l.johnson@cox.net>

From: Ron Johnson <ron.l.johnson@cox.net>
To: pgsql-general <pgsql-general@postgresql.org>
Date: 2018-03-12T18:14:26Z
Lists: pgsql-general
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.