ENV Variabale changes are not retained


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ENV Variabale changes are not retained
# 1  
Old 10-05-2010
ENV Variabale changes are not retained

ENV varibles set using a script are not retailed once the script execution is done. But if the same ENV variable is set in command line, it is retained.

Consider the below case

Code:
$ cat ti
export MDS_CODE_HOME=`pwd`
echo $MDS_CODE_HOME
rsamadde@pcasvs04 ~/R2ANew
$ ti
/export/home/rsamadde/R2ANew <- MDS_CODE_HOME is set here
rsamadde@pcasvs04 ~/R2ANew
$ echo $MDS_CODE_HOME
<- MDS_CODE_HOME not retaimed here
rsamadde@pcasvs04 ~/R2ANew
$ export MDS_CODE_HOME=`pwd` <- MDS_CODE_HOME is set here
rsamadde@pcasvs04 ~/R2ANew
$ echo $MDS_CODE_HOME
/export/home/rsamadde/R2ANew <-MDS_CODE_HOME is retaimed here
rsamadde@pcasvs04 ~/R2ANew
$

I am using SSH Client from in WIndows XP to login. The issue is with all users logging in from my machine. So this might be a SSH issue.
# 2  
Old 10-05-2010
Environment variables cannot travel "up stream" to the calling process.

When a programme is invoked, the current process' environment (exported variables in terms of the shell) is copied and becomes a part of the child process' allocated memory. Any changes to the environment by that process are made to its own copy which is deleted when the process terminates.

Logistically this is a good thing. If a script invokes a command, it would be chaos if the command changed the parent's environment variables.
# 3  
Old 10-05-2010
Nothing to do with SSH this is standard shell functionality as agama points out.

You need to execute your script in the current shell. Execute it like this:

Code:
$ . ti

# 4  
Old 10-06-2010
Thanks for the quick reply. In our project, it is configured in such a way that once you login and execute a script, it sets the ENV variables for that session and retains during the entire life. And this is working fine for all other users when they are loggin in from their PC's. But the same user when logging in from my PC, it is not working.

---------- Post updated at 09:59 PM ---------- Previous update was at 09:55 PM ----------

@Chubler_XL :
Executing it in local shell as "$ . ti" does not helpSmilie Please note this is not the actual script but the same script is working when logged in from different PC's. The problem is with the PC am using. And hence the thought of SSH Shell.

---------- Post updated at 10:04 PM ---------- Previous update was at 09:59 PM ----------

The issue is resolvedSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output of a Grep(Which already has a variable) into a Variabale

Hi All, I have a an array, in which i need to loop through all the variable and check each variable individually for a pattern. For ex #!/bin/ksh set -A FileNames $(</Temp/AllNames) echo "Total array elements :" ${#FileNames } for i in ${FileNames} do # if the "${i} | grep Last"... (3 Replies)
Discussion started by: baranisachin
3 Replies

2. Red Hat

Set Env

Hi, I need to add file the /usr/lib under the command set. The /usr/lib need to be set under the DIRS=' ' while listing the set command. I tried with the command below: export PATH=${PATH}:/usr/bin But this doesn't work out... (4 Replies)
Discussion started by: gsiva
4 Replies

3. Web Development

Deny from env=env-variable Does not work

(Above from Apache docs). On my system, using: SetEnvIf User-Agent Mozilla IsBad=1 Order allow,deny Allow from all Deny from env=IsBad ...I see that environment variable is set (using phpinfo()) but the page is still served. No errors in the Apache logs. (1 Reply)
Discussion started by: gnurob
1 Replies

4. Shell Programming and Scripting

env command

All, what is env command used for in Unix? Regards Oracle User (2 Replies)
Discussion started by: Oracle_User
2 Replies

5. Shell Programming and Scripting

declaring a variabale as string type

I know that directly we can assign a string to a variable but is there any other way to declare a variable as string type. I am using tcsh shell where I am using a function which would return a value of string type but when I am using return keyword , it is returning only integer value.pls help. (3 Replies)
Discussion started by: maitree
3 Replies

6. HP-UX

I want a HP-UX ENV,how could I?

just for practice,:) (1 Reply)
Discussion started by: freebsdjlu
1 Replies

7. UNIX for Dummies Questions & Answers

Env Variable

Hi, I have a doubt on Environment variable. I want to know where and when the envirnment variables are defined? Thanks & Regards, Siba (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

8. Shell Programming and Scripting

env

Hi, I want to check the path set for a particular variable.Like when i use "env" command ,so many variables are there.I have to search for that variable which i need.Instead can i have any cmd which i can directly check the path set for that variable except "echo $path_name" Thanks, ... (3 Replies)
Discussion started by: rrs
3 Replies

9. Shell Programming and Scripting

Adding command line env in cron env

Hello friends, i run two scripts manually & they work. i run them in cron & they don work. how to match the two env's 1.command line env 2.cron env i would like cron to use command line env. Thanks & Regards Abhijeet (1 Reply)
Discussion started by: abhijeetkul
1 Replies

10. Solaris

Env

hey guys!!!! i have a few question .. how to modify the user ENV in Sun Solaris 10 ... Thanks!!!! (1 Reply)
Discussion started by: giancarlodjabon
1 Replies
Login or Register to Ask a Question