"echo"ing a psql command in a bash script

From: Ennio-Sr <nasr(dot)laili(at)tin(dot)it>
To: psql-general(at)postgresql(dot)org
Subject: "echo"ing a psql command in a bash script
Date: 2004-09-02 20:54:14
Message-ID: 20040902205414.GA11554@deby.ei.hnet
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all!
I'm writing a script that presents the user with a numbered lines
menu, each line corresponding to a <case n> which executes a psql
command. As the psql-commands are very similar to each other (all of
them have the structure:

1.- psql mydb -x -c "SELECT * FROM tb_nm WHERE col_nm LIKE '%$k_r%'" )

I thought it was possible to shorten it, initializing a str with said
command at the beginning of the script and limiting the various case
lines to defining the col_nm and the $k_r to be searched, i.e.:

2. -
(once for all):
cmnd=echo psql mydb -x -c "SELECT * FROM tb_nm WHERE $col_nm LIKE '%$k_r%'"

(in each <case n>):
col_nm="....."
echo $cmnd
---------------------------
The point is that:
when I test command "1", the query result appears immediately on the
screen and disappears (leaving room to the script menu), when I press
"q"; i.e., the environment remains that of psql until I press "q", which
seems to be a correct behaviour;

whereas, testing command "2", first appears the menu again (as if the
query had been unsuccessfull) and then (after pressing Enter - which
normally would cause exiting the script) the query result shows.

Could somebody throw some light on this issue?
Thanks for your attention.
Ennio.

--
[Perche' usare Win$ozz (dico io) se ..."anche uno sciocco sa farlo. \\?//
Fa' qualche cosa di cui non sei capace!" (diceva Henry Miller) ] (°|°)
[Why to use Win$ozz (I say) if ... "even a fool can do that. )=(
Do something you aren't good at!" (used to say Henry Miller) ]

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vivek Khera 2004-09-02 20:59:46 Re: Foreign key locks
Previous Message Thomas F.O'Connell 2004-09-02 20:43:43 Re: How to determine a database is intact?