variable substitution in shell script

Moderator: NorbertKrupa

Post Reply
User avatar
nnani
Master
Master
Posts: 302
Joined: Fri Apr 13, 2012 6:28 am
Contact:

variable substitution in shell script

Post by nnani » Wed Jun 26, 2013 1:43 pm

Hello All,

I am trying to make a script which counts number of columns for a specific table.
The table name will be user input to the script

Code: Select all

#!/bin/ksh
tab_nm=$1
var=`vsql -At -h xxx.xxx.xx -d xxxxx -U xxx -v table_name='$1' -c "select count(column_name) from columns where table_name = ':table_name' group by table_name;"`
echo $var
This is not giving me any result.
I am not understanding how to substitiute the variable ':table_name' with the user input value.
Can anybody help me with this.
nnani........
Long way to go

You can check out my blogs at vertica-howto

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: variable substituition in shell script

Post by id10t » Wed Jun 26, 2013 5:59 pm

Hi!

Code: Select all

daniel@synapse:/tmp$ cat nnani.ksh 
#!/bin/ksh

/opt/vertica/bin/vsql -Atc "

SELECT COUNT(column_name) 
  FROM columns 
 WHERE table_name = '${1}' 
 GROUP BY table_name

"

Code: Select all

daniel=> select nnani('customer_dimension');
INFO 4427:  Procedure reported:
21

 nnani 
-------
     0
(1 row)

User avatar
nnani
Master
Master
Posts: 302
Joined: Fri Apr 13, 2012 6:28 am
Contact:

Re: variable substituition in shell script

Post by nnani » Thu Jun 27, 2013 6:38 am

Hello skwa,

I am not trying to create a external procedure.
It just a script which takes a user input value. My only problem is how do I make the variable ':table_name' take the input value by the user.
nnani........
Long way to go

You can check out my blogs at vertica-howto

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: variable substituition in shell script

Post by id10t » Thu Jun 27, 2013 10:11 am

Hi!

>> how do I make the variable ':table_name' take the input value by the user?
You can't.

Post Reply

Return to “Vertica and the Operating System”