Link to home
Start Free TrialLog in
Avatar of GlobexCorp
GlobexCorp

asked on

Shell script: How can I populate a shell script variable with result of sql statement

I want to populate a shell script variable with the result of a select count(*) sql statement. At the moment I can select the results and write them to a file but now I just want to get the count and populate a shell script varaiable with the value

i.e. I want the variable 'COUNT' to be populated with the result of 'Select count(*) from Table'

I'm a newcomer to shell scripting to so any help would be greatly appreciated

Thanks
Avatar of mahome
mahome
Flag of Germany image

COUNT=3 or export count=3, if you want call other scripts which want to use it. If you post your exisiting script we can give more hints.

$ COUNT=3
$ echo $COUNT
3

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GlobexCorp
GlobexCorp

ASKER

Thanks for the reply

I'm not sure of the username/password for the db, I'm working from someone elses code. I'm already accessing the DB so is there anyway of using that code without the inclusion of the user/pass?

Thanks
I am not aware of any other method to access database without username and password
At the moment I'm successfully outputting a sql select to a file without using username/password:

'CODE=echo "select max(col) from TestTable where col like 'A%'" | ac_bl -qs -|  ~/developers/bin/runparallel -l20000 -n30","' >> Test_File.csv

I'm not using the user/pass here so I figured it was possible to read from the db the same way and instead of writing to a file populate my variable
I think either ac_bl or ~/developers/bin/runparallel has the username and password