Re: "echo"ing a psql command in a bash script - Mailing list pgsql-general

From Jim Wilson
Subject Re: "echo"ing a psql command in a bash script
Date
Msg-id twig.1094222345.61185@kelcomaine.com
Whole thread Raw
In response to "echo"ing a psql command in a bash script  (Ennio-Sr <nasr.laili@tin.it>)
Responses Re: "echo"ing a psql command in a bash script
List pgsql-general
Ennio-Sr said:

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

That will be executed immediately, and give you an error.

> (in each <case n>):
> col_nm="....."
> echo $cmnd

I'm surprised you get anything.  AFAIK this should parse the files in your
directory into column names.  Maybe you are doing something slightly different?

Rather than setting the $cmnd variable, try using something like this:

echo mydb -x -c \"SELECT "*" FROM tb_nm WHERE $col_nm LIKE \'%$k_r%\'\" |
xargs psql

I'm not sure where you are storing your column names,  but if you can pipe it
as a list into the above you won't need to rum a loop in your script.  There
are a thousand ways to do this,  but most important is remember to quote the
"*" so the shell doesn't parse it.  BTW You did not say, so I'm also assuming
you are using "bash" or "sh" since that's what this looks like. :-)

Best,

Jim


pgsql-general by date:

Previous
From: "Russ Brown"
Date:
Subject: psql leaking?
Next
From: Wes
Date:
Subject: Re: How to determine a database is intact?