Welcome
Welcome to <strong>The Linux And Unix Menagerie</strong>.

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Unable to interpret environmental variable

Any unix or linux shell scripting questions and answers

Unable to interpret environmental variable

Postby unixmylife on Wed Apr 01, 2009 10:54 am

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
unixmylife
User
 
Posts: 1
Joined: Wed Apr 01, 2009 10:48 am

Postby laum on Wed Apr 01, 2009 11:17 pm

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
laum
Site Admin
 
Posts: 46
Joined: Sun Oct 14, 2007 7:04 pm


Return to Shell Scripting

Who is online

Users browsing this forum: No registered users and 0 guests

cron