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