Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evRy9-0001XD-IN for pgsql-general@arkaria.postgresql.org; Mon, 12 Mar 2018 18:14:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1evRy8-0003Qg-0V for pgsql-general@arkaria.postgresql.org; Mon, 12 Mar 2018 18:14:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1evRy7-0003QV-Os for pgsql-general@lists.postgresql.org; Mon, 12 Mar 2018 18:14:43 +0000 Received: from eastrmfepo103.cox.net ([68.230.241.215]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1evRxz-0004sX-0p for pgsql-general@postgresql.org; Mon, 12 Mar 2018 18:14:38 +0000 Received: from eastrmimpo209.cox.net ([68.230.241.224]) by eastrmfepo103.cox.net (InterMail vM.8.01.05.28 201-2260-151-171-20160122) with ESMTP id <20180312181426.WVDH22712.eastrmfepo103.cox.net@eastrmimpo209.cox.net> for ; Mon, 12 Mar 2018 14:14:26 -0400 Received: from [192.168.1.10] ([70.171.109.83]) by eastrmimpo209.cox.net with cox id M6ES1x0101o04Vy016ESze; Mon, 12 Mar 2018 14:14:26 -0400 X-Authority-Analysis: v=2.2 cv=LrHi8jVc c=1 sm=1 tr=0 a=uCHdjGDeLqaieW9t8IbZ6A==:117 a=uCHdjGDeLqaieW9t8IbZ6A==:17 a=x7bEGLp0ZPQA:10 a=T11QR6bd6vIA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=di6wyNHZUqcG5xjhqX4A:9 a=QEXdDO2ut3YA:10 a=1M38KatuuqIVJD8lGgwA:9 a=4HFTtz-mLzc3Zupp:21 a=_W_S_7VecoQA:10 X-CM-Score: 0.00 Authentication-Results: cox.net; auth=pass (PLAIN) smtp.auth=ron.l.johnson@cox.net To: pgsql-general From: Ron Johnson Subject: psql in a bash function Message-ID: <32feadd1-7601-6a39-9fb8-bd1d3544f2e2@cox.net> Date: Mon, 12 Mar 2018 13:14:26 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------5582FE6A95A74331AC6ECA1C" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------5582FE6A95A74331AC6ECA1C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. --------------5582FE6A95A74331AC6ECA1C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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.
--------------5582FE6A95A74331AC6ECA1C--