Page 1 of 1

variable substitution in shell script

Posted: Wed Jun 26, 2013 1:43 pm
by nnani
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.

Re: variable substituition in shell script

Posted: Wed Jun 26, 2013 5:59 pm
by id10t
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)

Re: variable substituition in shell script

Posted: Thu Jun 27, 2013 6:38 am
by nnani
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.

Re: variable substituition in shell script

Posted: Thu Jun 27, 2013 10:11 am
by id10t
Hi!

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