Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 633951337C38 for ; Wed, 13 Apr 2011 15:21:53 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 85465-02-4 for ; Wed, 13 Apr 2011 18:21:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 9B0A41337BFF for ; Wed, 13 Apr 2011 15:15:31 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p3DIFVlb065458 for ; Wed, 13 Apr 2011 18:15:31 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p3DIFV3N065457; Wed, 13 Apr 2011 18:15:31 GMT (envelope-from www) Date: Wed, 13 Apr 2011 18:15:31 GMT Message-Id: <201104131815.p3DIFV3N065457@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #5978: Running postgress in a shell script fails From: "Paul Deschamps" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201104/83 X-Sequence-Number: 30002 The following bug has been logged online: Bug reference: 5978 Logged by: Paul Deschamps Email address: pdescham49@gmail.com PostgreSQL version: 8.4.6 Operating system: Ubuntu 10.4 Description: Running postgress in a shell script fails Details: When running postgres in a shell using the -c option it looks as though it parses the contents of the --command as command line arguments. ---BEGIN SCRIPT--- #!/bin/bash psql --version PCOMMAND='psql postgres -c"SELECT tablename FROM PG_TABLES limit 1;"' echo "PGSQL - Execution from a shell script test" echo echo "Running Command:"${PCOMMAND} echo "TEST 1 " OUTPUT1=$(${PCOMMAND}) echo $OUTPUT1 echo echo "TEST 2" OUTPUT2=`$PCOMMAND` echo $OUTPUT2 echo echo "TEST 3" OUTPUT3=`exec $PCOMMAND` echo $OUTPUT3 echo echo "TEST 4" $PCOMMAND echo "TEST 5" psql postgres -c"SELECT tablename FROM PG_TABLES limit 1;" ---END SCRIPT--- ---BEGIN OUTPUT--- [postgres@host03 scripts]$ ./test.sh psql (PostgreSQL) 8.4.6 PGSQL - Execution from a shell script test Running Command:psql postgres -c"SELECT tablename FROM PG_TABLES limit 1;" TEST 1 psql: warning: extra command-line argument "FROM" ignored psql: warning: extra command-line argument "PG_TABLES" ignored psql: warning: extra command-line argument "limit" ignored psql: warning: extra command-line argument "1;"" ignored psql: FATAL: role "tablename" does not exist TEST 2 psql: warning: extra command-line argument "FROM" ignored psql: warning: extra command-line argument "PG_TABLES" ignored psql: warning: extra command-line argument "limit" ignored psql: warning: extra command-line argument "1;"" ignored psql: FATAL: role "tablename" does not exist TEST 3 psql: warning: extra command-line argument "FROM" ignored psql: warning: extra command-line argument "PG_TABLES" ignored psql: warning: extra command-line argument "limit" ignored psql: warning: extra command-line argument "1;"" ignored psql: FATAL: role "tablename" does not exist TEST 4 psql: warning: extra command-line argument "FROM" ignored psql: warning: extra command-line argument "PG_TABLES" ignored psql: warning: extra command-line argument "limit" ignored psql: warning: extra command-line argument "1;"" ignored psql: FATAL: role "tablename" does not exist TEST 5 tablename ----------- pg_type (1 row) ---END OUTPUT---