Page 1 of 1

Unable to interpret environmental variable

PostPosted: Wed Apr 01, 2009 10:54 am
by unixmylife
Hi All,

I am coding a script which is intended to do the following :
1. I fetch a column from the oracle table which has sql statement.
For ex: select column1 from table1 where column2=${env_var_value}

2. I have set the environmental variable in my Solaris OS.
I fetch this column value into a variable and I have to run the statement.

Now the problem is that when I fetch the column value into a variable in my program, the environmental variable doesn't get interpreted.
It just places the column value i.e., select column1 from table1 where column2=${env_var_value} without substituting the env_var_value..


Request your precious guidance and help in this regard.

Thanks in advance

PostPosted: Wed Apr 01, 2009 11:17 pm
by laum
Hey There,

Thanks for stopping by this little part of the wasteland ;)

If I understand you correctly, the problem may be with the scope of the variable itself.

If you're setting the variable in your Solaris environment, and then calling a script that uses that variable, it may or may not inherit the value from your environment depending upon how it's called. Technically, you're running a subshell of your user shell and the subshell the script run in should inherit the values of most environment variables form your user shell. Any number of things can go wrong, though, and running it indirectly causes the greatest amount of problems is that area.

I've often found the best way to get around this is to include the variable in a file-permissions-protected (if that's even necessary) file and source that from within the script.

e.g.

host # cat env_file

VAR=value

host # cat my_program

#!/bin/bash

. /full/path/to/your/env_file

This will solve the issue 9 times out of 10. If I'm misunderstanding you, please write back and I'll be happy to help you out :)

Best wishes,

Laum