![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do i set environment variable | ahjiefreak | Linux | 4 | 01-20-2008 08:21 PM |
| sed on an environment variable ? | lumix | Shell Programming and Scripting | 3 | 12-15-2007 06:30 PM |
| set environment variable? | kohoutek | UNIX for Advanced & Expert Users | 3 | 12-21-2005 05:23 PM |
| Environment Variable | karyn1617 | Shell Programming and Scripting | 2 | 02-04-2005 03:36 PM |
| Environment Variable | jacobsa | UNIX for Dummies Questions & Answers | 8 | 06-03-2002 04:02 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Using Environment Variable
In our current environment we have each of our testing levels on individual servers (running Korn shell). So, there is a server for dev and test, and 2 servers for qa and prod. I have several scripts that utilize a code that is dependant on the server where it resides. While I was the only person using these scripts, I had that value hard coded in my scripts (they were quick and dirty scripts). Now we have several folks that will be supporting this and I want to keep the scripts in a central repository and change this value to be an environment variable.
My thought is to set this as an environment variable in the users .profile. Then the scripts will use that variable, instead of having to change it for each server/test level. My assumption, and from everything I've read, is that if I export the variable in my profile, it should be available to scripts when executed. But, that is not what I am seeing. And these scripts are executed by the user from the command line. Here is an example. Any help would be appreciated. .profile: VAR=server_a export $VAR script: some_command $VAR #executes command passing in $VAR When I do this, $VAR does not seem to contain server_a. It is empty instead. However, if I echo out $VAR at the command line, it does equal server_a. A solution that does seem to work, is to set the variable in a .kshrc file and execute that in my script prior to using it. But I would prefer to have it set in the profile and have it available for the scripts. Any help would be appreciated. Thanx |
|
||||
|
/etc/profile and $HOME/.profile are sourced for login (Bourne compatible) shells.
That's probably why you see the exported variables set when you echo them from your login shell. On the other hand if you need special settings for your sub shells as well then export ENV in your .profile and let it point to an appropiate .shrc file in your HOME Refer to the FILES section in the manpage of your shell. Also note that if your script is for instance run from a cron job that it only gets a pretty rudimentary environment (see man crontab). As for host or node names, I often have such an export in my .profile (you may have to separate assignment and export to two lines, and use backticks if you don't have a Posix shell) export NODENAME=$(/usr/bin/uname -n) |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|